This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC 3.1.1
- From: Erik Trulsson <ertr1013 at student dot uu dot se>
- To: Rob Taylor <robt at flyingpig dot com>
- Cc: Andreas Schwab <schwab at suse dot de>, Jack Lloyd <lloyd at acm dot jhu dot edu>, Toon Moene <toon at moene dot indiv dot nluug dot nl>, gcc at gcc dot gnu dot org, shimon at simon-shapiro dot com
- Date: Fri, 28 Jun 2002 12:30:59 +0200
- Subject: Re: GCC 3.1.1
- References: <je660326xk.fsf@sykes.suse.de> <020a01c21e8d$45433690$9b00a8c0@highend.co.uk>
On Fri, Jun 28, 2002 at 11:19:22AM +0100, Rob Taylor wrote:
>
> Andreas Schwab <schwab@suse.de> writes:
> > 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.
>
> why? x is an unsigned long long, surely << should be defined for values up to 63
> for this implementation?
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.
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se