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

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

Re: [avr-gcc-list] Bug in shift operation with avr-gcc


From: David Kelly
Subject: Re: [avr-gcc-list] Bug in shift operation with avr-gcc
Date: Tue, 7 Jun 2011 13:39:17 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Jun 07, 2011 at 12:17:45PM -0600, Weddington, Eric wrote:
> 
> > uint32_t  t1;
> > int main(){
> >     t1=0xf << (12);    // t1 gets fffff000 instead of 0000f000
> > }
> 
> uint32_t  t1;
> int main(){
>     t1=0xfUL << (12);    // t1 gets fffff000 instead of 0000f000
> }

Celio, 0x0f is getting shifted left 12 bits into an int16_t (the AVR
default variable type) before being promoted to an uint32_t which is
when the sign bit gets stretched out.

Eric's version expands 0x0f into uint32_t first, before the shift.

-- 
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.



reply via email to

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