Casting Signed to Unsigned: Undefined Behavior?
Hi,
First take a look at this quote from the C++03 standard:

Originally Posted by
4.7 Integral conversions
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source
integer (modulo 2n
where n is the number of bits used to represent the unsigned type). [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). ]
This is the closest thing I can find in the standard that explains this behavior:
unsigned int Foo = (int)-4;
I would think this is implementation-specific behavior (Or undefined behavior). I have two questions:
1) What is the dummy's translation of the quoted standard rule above?
2) What does the standard say about the code snippet above (Assigning signed to unsigned)?
Thanks.
--MrDoomMaster
--C++ Game Programmer
Don't forget to rate me if I was helpful!