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]

Re: GCC 3.1.1


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.


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