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 14:08:14 +0100
User-agent: Mozilla Thunderbird 1.5.0.9 (X11/20061219)

Bob Paddock ha scritto:
The "falls out" is the issue with me, as I see the {} as being "contained 
within",
the "}" was never crossed, so to me it was still the same {} block.  I could not
find this "reinitialize" issue in my old K&R book?

The condition of the loop must me somehow checked. When you reach the "}", the execution crosses braces boundary and jumps to the check of for loop condition. If you write:

for (;;)
{
        ...
}

the condition is not well visible, as it has been omitted, but think if you write:

for (i = 0; i < 10; i++)
{
        ...
}

when the execution reaches the "}", jumps to:

i < 10

and if the condition is true the block is re-executed from the beginning. So variables declared inside the block die and reborn at every round.

You can see very well this behavior with a step-by-step debugger execution: when executing a loop, if you reach the block end, the execution jumps to the line containing the loop condition, crossing braces boundary.



--
_|/ 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]