Signed overflow optimization hazards in the kernel
Posted Aug 17, 2012 6:45 UTC (Fri) by wahern
In reply to: Signed overflow optimization hazards in the kernel
Parent article: Signed overflow optimization hazards in the kernel
You have that in reverse. Conversion to unsigned is always well defined. Conversion to signed where the value cannot be represented is implemented-defined:
C99 22.214.171.124 Signed and unsigned integers
- When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.
- Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.49)
- 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.
to post comments)