for != while

Brett Galloway brett at wjvax.UUCP
Fri Sep 5 05:40:30 AEST 1986


In article <86900030 at haddock> version B 2.10.3 4.3bsd-beta 6/6/85; site wjvax.wjvax.UUCP wjvax!qubix!saber!sun!decwrl!pyramid!hplabs!qantel!lll-lcc!lll-crg!nike!think!ima!haddock!karl karl at 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 understand why.  The value "inner" is associated with the variable
foo with scope inside the for loop (within the {}'s).  The value "outer"
is associated with the variable foo with scope outside the for loop (outside
the {}'s).  The printf(foo) is outside the for loop scope, so it should
print "outer".

-- 
-------------
Brett Galloway
{pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett



More information about the Comp.lang.c mailing list