GCC 3.1.1

Dale Johannesen dalej@apple.com
Fri Jun 28 14:22:00 GMT 2002


On Friday, June 28, 2002, at 12:33 AM, Andreas Schwab wrote:

> Jack Lloyd <lloyd@acm.jhu.edu> writes:
>
> |> Basically:
> |>
> |> unsigned long long x;
> |> x = 1 << 32;
> |>
> |> results in x == 0 rather than 0x100000000 as the code expects.
>
> Actually this is already undefined by itself, and even x == 0 is not
> guaranteed.

Yes.  It will be 1 on some machines (when the shift count is truncated
to 5 bits, thus 0).  The result may vary with optimization level, and
depend on whether the 1 or the 32 is a constant or in a variable.
In short, don't do that.

1LL << 32 should do what you want.



More information about the Gcc mailing list