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: Bob Paddock
Subject: Re: [avr-gcc-list] Should this code work? 4.1.1
Date: Fri, 2 Mar 2007 20:31:40 -0500
User-agent: KMail/1.9.5

On Friday 02 March 2007 18:42, Francesco Sacchi wrote:
> 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.

"ISO/IEC 9899:TC2 Committee Draft — May 6, 2005 WG14/N1124
6.2.4 Storage durations of objects
...
4 An object whose identifier is declared with no linkage and without the 
storage-class
specifier static has automatic storage duration.

5 For such an object that does not have a variable length array type, its 
lifetime extends
from entry into the block with which it is associated until execution of that 
block ends in
any way. (Entering an enclosed block or calling a function suspends, but does 
not end,
execution of the current block.) If the block is entered recursively, a new 
instance of the
object is created each time. The initial value of the object is indeterminate. 
If an
initialization is specified for the object, it is performed each time the 
declaration is
reached in the execution of the block; otherwise, the value becomes 
indeterminate each
time the declaration is reached."

for(;;){} is a endless loop, how is "until execution of that block ends in any 
way." 
being fulfilled here?  I my mind the {} block should not have "ended", nor is 
this
a case of recursion, to cause 'shift' to be recreated and reinitialized.  
Apparently
it is the last paragraph that got me: "If an initialization is specified for 
the object,
it is performed each time the declaration is reached in the execution of the 
block;
otherwise, the value becomes indeterminate each time the declaration is 
reached."





reply via email to

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