I am seeing an odd behavior and was wondering if it was a bug. In X86_64, Gcc is sign extending a bit shift operation when assigned to an unsigned long. Specifically:
#include <stdio.h>
int main(){
unsigned long val;
val = (1 << 31);
printf("Val = %lx\n", val);
return 0;
}
This results in:
Val = 0xffffffff80000000;
Should the result be 0x80000000? I understand that the bit shift is a
32 bit operation, but shouldn't the compiler then up convert that to a
64 bit unsigned long?
Thanks.
-dan
