V
viza
Hi all
int i= INT_MIN;
unsigned int u= -i;
Is u guaranteed to have the absolute value of INT_MIN?
Why it might not: -i has type (int), and -INT_MIN might be more than
INT_MAX.
A cast might not work either, because in (unsigned)-i; the cast is too
late, and in -(unsigned)i then i cannot be represented as unsigned.
If long is longer than int, I can do -(long)i, but what if we are talking
about the longest integer type available?
TIA
viza
int i= INT_MIN;
unsigned int u= -i;
Is u guaranteed to have the absolute value of INT_MIN?
Why it might not: -i has type (int), and -INT_MIN might be more than
INT_MAX.
A cast might not work either, because in (unsigned)-i; the cast is too
late, and in -(unsigned)i then i cannot be represented as unsigned.
If long is longer than int, I can do -(long)i, but what if we are talking
about the longest integer type available?
TIA
viza