🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9282

Re: for != while

#9282
From: SCHEUTZOW,MICHAEL J
Date: Wed, 03 Sep 1986 17:08
38 lines
1532 bytes
> >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".
> 
> 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...
> 
> Kenneth R. Ballou                ...!ucbvax!brahms!ballou

It took me a few minutes to figure out what Ken was saying, and he is 
quite right.  The above is equivalent to:

main()
{
char *foo = "outer";

    for (;;)
        {
            {
	    char *foo = "inner"; /* note the 'char' */
            }
        printf(foo);
        exit(0);
	}
}

Mike Scheutzow         "I _think_ these are my opinions;
Georgia Tech           let me ask my boss..."
gt6294b@gitpyr.uucp
Technical Details
Message-ID: <2211@gitpyr.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!gatech!gitpyr!gt6294b
References: <86900030@haddock> <15525@ucbvax.BERKELEY.EDU>

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!gatech!gitpyr!gt6294b
From: gt6294b@gitpyr.UUCP (SCHEUTZOW,MICHAEL J)
Newsgroups: net.lang.c
Subject: Re: for != while
Message-ID: <2211@gitpyr.UUCP>
Date: Wed, 3-Sep-86 13:08:35 EDT
Article-I.D.: gitpyr.2211
Posted: Wed Sep  3 13:08:35 1986
Date-Received: Tue, 9-Sep-86 23:52:46 EDT
References: <86900030@haddock> <15525@ucbvax.BERKELEY.EDU>
Organization: Georgia Institute of Technology
Lines: 38