Re: Possible issue with integer promotion for << and >> in gcc.4.5.3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 18, 2012 at 5:44 PM, Arthur Schwarz <aschwarz1309@xxxxxxx> 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:
http://c-faq.com/expr/preservingrules.html .

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux