468,469 Members | 1,966 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

Is it correct to call string::substr(npos+1)?

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.

Sep 18 '06 #1
5 2788
Alien wrote:

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.
The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.

Best regards,

Tom

Sep 18 '06 #2
So, it's not defined in the standard?

Thomas Tutone wrote:
Alien wrote:

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.

The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.

Best regards,

Tom
Sep 18 '06 #3
Alien wrote:
npos is defined as -1, in both SGI and VS.
Actually, it is defined that way in the standard [21.3/6]

So npos+1=0?
As long as npos is an unsigned integral type (which it is): yes.

I remember that I read a book saying that npos+1==npos.
Well, that would be false.
Best

Kai-Uwe Bux
Sep 18 '06 #4
Thomas Tutone wrote:
Alien wrote:

npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.
The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.
Alien wrote:
So, it's not defined in the standard?
Kai-Uwe Bux has proven me wrong. It's defined in std::basic_string as
const size_type npos = -1;

I would have sworn Jossutis said it was implementation-defined.

Sorry to lead you astray.

Best regards,

Tom

Sep 18 '06 #5
Thomas Tutone wrote:
>Thomas Tutone wrote:
>>Alien wrote:
npos is defined as -1, in both SGI and VS.
So npos+1=0?
I remember that I read a book saying that npos+1==npos.
The value of npos is implementation defined. On many platforms it is
-1, but there is no requirement that that be the case. So don't rely
on it.

Alien wrote:
>So, it's not defined in the standard?

Kai-Uwe Bux has proven me wrong. It's defined in std::basic_string as
const size_type npos = -1;

I would have sworn Jossutis said it was implementation-defined.
He should have been right, except that it was originaly unspecified, not
implementation defined. Its purpose was to provide a sentinel value,
nothing more. Somehow unspecified got changed to -1, and that's led far
too many people to write code based on that particular value.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Sep 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Steve | last post: by
2 posts views Thread by Jarek Bednarz | last post: by
7 posts views Thread by Marcus Kwok | last post: by
25 posts views Thread by electrixnow | last post: by
12 posts views Thread by Simon | last post: by
5 posts views Thread by Gary Wessle | last post: by
11 posts views Thread by Christopher Pisz | last post: by
11 posts views Thread by xyz | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.