avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] odd left-shift behavior, avr-gcc 4.1.2


From: Dmitry K.
Subject: Re: [avr-gcc-list] odd left-shift behavior, avr-gcc 4.1.2
Date: Mon, 10 Dec 2007 09:59:20 +1000
User-agent: KMail/1.5

On Monday 10 December 2007 09:30, John Regehr wrote:
> > operand."  I believe this means that the result of the shift in your
> > example is a uint16_t, so you get 0xfffe which is then promoted to an
> > int32_t on assignment to x.
>
> Ok but notice that the same code gives a different result on x86-gcc.  I
> think this means that the only choices are: implementation defined
> behavior, undefined behavior, or compiler bug.

Yes, this is wrong behavior for original K&R C language in AVR case.

Letter it was change, see C99-Rationale: 

   QUIET CHANGE IN C89 (yes, 89)
   Shifting by a long count no longer coerces the shifted operand
   to long.

x86-gcc gives an another result due to 32-bit integer: left
operand is short (16-bit), but first it is promoted to int,
i.e. 32 bits.  And result is int (0x1fffe).

Regards,
Dmitry.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]