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

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

Re: [avr-gcc-list] Should this code work? 4.1.1


From: Francesco Sacchi
Subject: Re: [avr-gcc-list] Should this code work? 4.1.1
Date: Sat, 03 Mar 2007 00:42:06 +0100
User-agent: Mozilla Thunderbird 1.5.0.9 (X11/20061219)

Bob Paddock ha scritto:
you see that the last rjmp is jumping to the point where shift
is reinitialized with '1' (r18/r19).

Moving 'uint16_t shift = 1;' out of the for(;;){} and into
the top of main(){} makes the code work ok.

Is it my understanding, or the compiler that is broken here?

Nothing is broken.
If you declare shift inside the for block, every time block is executed shift is recreated.
As James said, with optimizations turned on, the code

if (0 == shift)
...

is optimized away, while if you add volatile you deny the compiler the assumption that the variable will not be modified, forcing to generate the code that use it. However, even with volatile keyword, the code cannot work as you intend because every time the loop ends shift die and borns again on loop start, initialized with 1.



--
_|/ Francesco Sacchi - Develer S.r.l., R&D dept.
 |\ http://www.develer.com/




reply via email to

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