Is the following guaranteed to work or implementation defined?
unsigned int a = 4294967294;
signed int b = a;
The value of b is -2 on gcc.
From C99
(§6.3.1.3/3) Otherwise, the new type is signed and the value cannot be
represented in it; either the result is implementation-defined or an
implementation-defined signal is raised.
The conversion of
avalue tosigned intis implementation-defined (as you correctly mentioned because of 6.3.1.3p3) . On some systems for example it can beINT_MAX(saturating conversion).For
gccthe implementation behavior is defined here:http://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html