This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]