[Top][All Lists]
[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: |
Dean Ferreyra |
Subject: |
Re: [avr-gcc-list] odd left-shift behavior, avr-gcc 4.1.2 |
Date: |
Sun, 09 Dec 2007 16:02:09 -0800 |
User-agent: |
Thunderbird 2.0.0.9 (Windows/20071031) |
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.
The native int size on your x86 compiler is probably 32 bits. Each
argument to the shift is promoted to int first; that's the bit about
"integer promotions" and this gets you answer you're expecting. I
believe the native int size on avr-gcc is 16 bits, so your left operand:
((uint16_t)0xffffL)
stays at 16 bits on the AVR.
Dean