Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!caip!nike!ucbcad!ucbvax!hplabs!amdahl!fai!wjvax!brett From: brett@wjvax.UUCP (Brett Galloway) Newsgroups: net.lang.c Subject: Re: for != while Message-ID: <755@wjvax.wjvax.UUCP> Date: Thu, 4-Sep-86 15:40:30 EDT Article-I.D.: wjvax.755 Posted: Thu Sep 4 15:40:30 1986 Date-Received: Sun, 7-Sep-86 04:08:43 EDT References: <86900030@haddock> Reply-To: brett@wjvax.UUCP (Brett Galloway) Organization: Watkins-Johnson Co., San Jose, Calif. Lines: 25 In article <86900030@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@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