Menu

#151 Invalid assignment with (un)signed numbers

open
aurelius
libenglab (121)
5
2008-07-24
2008-07-24
No

using 32bit architecture
signed long is in range [-2147483648,2147483647]
the following code has unexpected results:

signed long l;
l=2147483648
l=
0
(l should have underflowed to -2147483648)

but the following code works:
signed long l;
l=2147483647
l=
2147483647
l++;
l=
-2147483648
(underflowed correctly)

The above error exists in unsigned numbers too:
unsigned long u;
u=2147483648
u=
0
(value 2147483648 is well withing the limits of a 32bit unsigned integer)
s=2147483647
s=
2147483647
s++
s=
2147483648

So obviously there is error in parsing the numeric string

Discussion