This is the mail archive of the
mailing list for the GCC project.
Re: Possible issue with integer promotion for << and >> in gcc.4.5.3
- From: Ian Lance Taylor <iant at google dot com>
- To: Arthur Schwarz <aschwarz1309 at att dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 18 Dec 2012 21:49:28 -0800
- Subject: Re: Possible issue with integer promotion for << and >> in gcc.4.5.3
- References: <1355870392.38278.YahooMailRC@web181306.mail.ne1.yahoo.com> <CAKOQZ8xzLJFBTC6=UoUKxGtVES80y8mwRgaamFatw1G_Lc0m5g@mail.gmail.com> <1355881440.33098.YahooMailRC@web181304.mail.ne1.yahoo.com>
On Tue, Dec 18, 2012 at 5:44 PM, Arthur Schwarz <firstname.lastname@example.org> wrote:
> I don't see how I misread the output. The output shows that char <op> long
> promotes to LONG except for the shift operations. char <op> ulong promotes to
> ULONG except shift operations promote to INT.uchar <op> long promotes to LONG (I
> would have expected ULONG) except for shift operations which promote to INT.
> uchar <op> ulong promotes to ULONG except for shifts and long <op> ULONG
> promotes to ULONG except for shifts.
> Can you explain how I have misread the output and/or what the standard defines
> as the correct promotion?
> I am at this stage very confused as to what is correct and what is not. If the
> output defines the correct output (which it might) then it seems inconsistent as
> well as inconsiderate.
In your earlier message you said that long << long results in int, but
it doesn't; it results in long.
The types you list in the message quoted above all look correct to me
at first glance.
You say that you would expect uchar op long to result in ulong, but it
actually results in long. In general C/C++ are value preserving, not
signedness preserving (K&R C was signedness preserving, but that was
superseded by ISO C in 1989). So given uchar op long the uchar is
promoted to long, since long can represent all the values of uchar.
Then long op long results in long as one would expect.
What other operations look wrong to you?
And actually, before you reply, consider this: this is not a GCC
issue. GCC is simply implementing the language standards, so you
should ask about the language, not about GCC. Read this: