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: Char shifts promoted to int. Why?


On Monday 18 December 2006 17:53, Robert Dewar wrote:
> Chris Lattner wrote:
> > C99 says:
> >
> > The integer promotions are performed on each of the operands. The
> > type of the result is
> > that of the promoted left operand. If the value of the right operand
> > is negative or is
> > greater than or equal to the width of the promoted left operand, the
> > behavior is undefined.
> >
> > Thus, it is undefined.
>
> So the suggested transformation is indeed valid, which is what I
> thought, but some seem to be contesting this, though I don't see
> on what grounds.

Note that the shift value restriction is based on the *promoted* type.
Shifting an 8-bit value by >=8 is undefined. However in this case we're 
shifting a 32-bit value, because the left operand has been promoted. The fact 
that the variable written i the source happens to be a char is irelevant.

Paul


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