
Originally Posted by
laserlight
Change the %x format specified to %d. You will probably find that some of the values are negative. Bitwise right shift of a signed integer with a negative value has an implementation defined result, e.g., maybe the bits were right shifted with 1 bits used to fill in the "shifted positions", thereby retaining the sign.
Thanks Laserlight. You're right. When I change the printf to the following...
Code:
printf("%x, %x, %x\n", (1 << 31), ((0x80000000) >> 31), (((uintptr_t)1 << 31) >> 31));
..it "works". The result is: 80000000, 1, 1.
Cheers