[Top][All Lists]

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

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

From: Graham Davies
Subject: Re: [avr-gcc-list] Should this code work? 4.1.1
Date: Sat, 03 Mar 2007 09:03:43 -0500

Bob Paddock wrote:
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.

Let's look at it another way. Is there anything inside the braces that says "let's do all this over and over". There isn't. The thing that says to do it over is outside the braces. So, control has to leave the sequence of statements inside the braces (the block) to get to the part that says do it again.

 I could not find this "reinitialize" issue in my old K&R book?

I can't help you there as I don't find K&R very good is this way. What you're looking for many not be in one place. You may have to put it together from an understanding of control statements (such as for), blocks and the lifetime of automatic variables. You should realize that if the lifetime of a variable ends you are supposed to infer that if it is brought back to life by re-entering its block it cannot be expected to have its old value. Initialization of automatic variables takes place at the start of their lifetime (afterwards, it's assignment, not initialization.) You may never find this explained as "reinitialization" because that isn't what it is. The old one is gone. The new one is initialized, not reinitialized.

I don't see while(true){} being any different than for(;;){}
in this context, and while(true){} causes the Lint error
of "evaluation of constant value boolean".

There is no difference in effect. What I'm suggesting is that when you're trying to puzzle out what will happen when control reaches the end of the block, it's easier to see that the while condition is re-evaluated to decide whether to repeat the block than to figure out that control goes into a for statement that is apparently empty of executable content.

I can't see why Lint would consider this an error and for ( ; ; ) not. Even so, isn't there some markup you can add in a comment to reassure Lint that this is what you intend?


reply via email to

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