🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9224

Re: for != while

#9224
From: Kenneth R. Ballou
Date: Tue, 02 Sep 1986 20:55
28 lines
1618 bytes
In article <86900030@haddock> karl@haddock writes:
>
>It's well known that the equivalence between for and while breaks down if
>there's a "continue" statement.  Here's another case I just discovered:
>
>main() {
>	char *foo = "outer";
>	for (;; printf(foo),exit(0)) {
>		char *foo = "inner";
>	}
>}
>
>This prints "outer" (vax SVR2 compiler), though the for-while equivalence
>might lead one to expect "inner".

I don't think the issue here is equivalence of for and while statements.
The point is that the scope of the inner 'foo' is the compound statement
which is the body of the for statement.  So, quite rightly, the 'foo'
given as the argument to printf in the third expression of the for statement
refers to the most closely nested declaration of 'foo' -- the body of the
for statement is one block level higher and is not visible at this point.

---------------

Kenneth R. Ballou                ...!ucbvax!brahms!ballou
Dept. of Mathematics
University of California
Berkeley, California  94720
Technical Details
Message-ID: <15525@ucbvax.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!nike!ucbcad!ucbvax!brahms!ballou
References: <86900030@haddock>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!nike!ucbcad!ucbvax!brahms!ballou
From: ballou@brahms.BERKELEY.EDU (Kenneth R. Ballou)
Newsgroups: net.lang.c
Subject: Re: for != while
Message-ID: <15525@ucbvax.BERKELEY.EDU>
Date: Tue, 2-Sep-86 16:55:22 EDT
Article-I.D.: ucbvax.15525
Posted: Tue Sep  2 16:55:22 1986
Date-Received: Tue, 2-Sep-86 21:28:43 EDT
References: <86900030@haddock>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: ballou@brahms.UUCP (Kenneth R. Ballou)
Organization: University of California, Berkeley
Lines: 28