This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
X86_64 bit shifts
- From: "Wachdorf, Daniel R" <drwachd at sandia dot gov>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 6 Jul 2007 06:06:43 -0600
- Subject: X86_64 bit shifts
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