X86_64 bit shifts

Daniel Jacobowitz drow@false.org
Fri Jul 6 12:28:00 GMT 2007

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 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?

No, a signed 32-bit integer is always sign extended when promoted to
64-bit.  If you have C99 handy, see section (Signed and
unsigned integers).

Daniel Jacobowitz

More information about the Gcc mailing list