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


Erik Trulsson wrote:
> x is an unsigned long long, yes, but 1 is not. An unadorned 1 has type
> int.  This means that the RHS of the expression above has type int and
> will be evaluated as such.  (And if an int has 32 bits or less the
> expression won't be well-defined.)  This value will then be assigned to
> x. In C the type of a variable on the left side of an assignment does
> not influence how the right hand side is evaluated.
> 
> If you want the expression to work "as expected" I think
>  x = 1LL << 32 
> should do the trick.

Note that 1LL << 63 is not well-defined (although it is fine with GCC).
1ULL << 63 is well-defined, though, and it would seem to make more sense
in this example because x is unsigned.

-- Jamie


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