|
-
August 3rd, 2010, 01:04 PM
#5
Re: signed to unsigned (and vice versa)
 Originally Posted by laserlight
Yes, except that the standard does define what happens if the value "can be represented in the destination type".
I am not sure if an implementation is permitted to differ as long as the net effect is the same, but the C++ standard does indeed define how npos should be defined, i.e., by initialising it with -1.
You might want to read paragraph 2 of section 4.7 of the 2003 edition of the C++ standard again. In particular, the comment on two's complement representation is a good hint as to why you are mistaken.
You probably mean the
...
[Note: In a two's complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). ]
...
Maybe I am dump but I can't see from that hint why a non-two's complement of -1 necessarily must be casted to an unsigned integer with all bits set.
Isn't it just 'implementation-defined' ?
(Even if so, the npos also would work if it is not the highest unsigned integer).
Regards, Alex
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|