Hi, the following is compiled in 9.3, glibc-2.3.4-23.4, and gcc-3.3.5-5. The result is: mask=0 mask1=4294967295
I would expect mask = mask1 = 0?
Regards, Verdi
=========================================================== #include
int main() { unsigned int mask = (unsigned int) -1 >> 32;
int i = 0; unsigned int mask1 = ((unsigned int) -1) >> (32 - i);
printf("mask=%u mask1=%u\n", mask, mask1); return 0; } =========================================================== Marcus' comment that this is an undefined behavior is absolutely correct (ISO C90 6.5.7), so if your code relies on mask1 (or mask) resulting in 0 is
On Wednesday 20 July 2005 5:57 am, Verdi March wrote:
probably a bad assumption and the code should be corrected.
Apparently what is happening in the second case is that ((unsigned int) -1)
is being changed to a signed int, and the sign bit is getting propagated.
BTW: On a 64-bit system (Itanium) the values are both 0.
--
Jerry Feldman