Re: X86_64 bit shifts

2007-07-06 Thread Michael Meissner
On Fri, Jul 06, 2007 at 06:06:43AM -0600, Wachdorf, Daniel R wrote: > 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 > > int main(){ > > unsigned long v

Re: X86_64 bit shifts

2007-07-06 Thread Daniel Jacobowitz
On Fri, Jul 06, 2007 at 06:06:43AM -0600, Wachdorf, Daniel R wrote: > val = (1 << 31); Try 1UL << 31 instead. > Should the result be 0x8000? 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? No, a signed

X86_64 bit shifts

2007-07-06 Thread Wachdorf, Daniel R
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 int main(){ unsigned long val; val = (1 << 31); printf("Val = %lx\n", val); return 0; } This resu