9 jan 2014 kl. 14.37 skrev Jim Jagielski:
However, if a is 4,294,967,200, then the behavior of (int)a is undefined and implementation dependent, since you can't express that value within the limits of a signed int (assuming 32 bits).
No, it's not undefined but implementation-defined, which means that an implementation can decide what to do as long as it documents it. There is quite a difference.
All compilers I have ever used, and then some, treat conversions to signed by modular reduction into the interval defined by that type. Nothing else makes sense, and compilers won't start doing it differently.
My point is that the possibility in that case of (int)a resulting in 0 is pretty freakin' remote, even if it is undefined behavior ;)
It's not undefined behaviour.
