"RoSsIaCrIiLoIA" <n@esiste.ee> wrote in message
news:mb********************************@4ax.com...
if
{
unsigned u = -INT_MIN;
-INT_MIN is performed using signed int arithmetic (before the assignment), and it can
overflow (undefined behaviour).
Note that even if you do...
unsigned u = INT_MIN;
u = -u;
You have no guarantee that u will be the magnitude of INT_MIN. Since UINT_MAX can equal
INT_MAX, you might have u == 0.
int i, sign = -1;
i = sign * u;
then i == INT_MIN or not?
sign * u will be performed in unsigned int arithmetic, so the result will always be
positive. The conversion on assignment to i will be implementation defined if the value is
outside the range [0..INT_MAX]. So, it could theoretically set i to anything. C99 even
allows an implementation defined signal to be raised.
Even C99 (optional) intN_t types, whilst necessarily unpadded twos complement integers,
are not immune from implementation defined conversions and potential signals if assigned a
value that is outside their range.
--
Peter