🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #319

Re: for != while

#319
From: karl
Date: Fri, 19 Sep 1986 00:24
31 lines
1910 bytes
mmintl!franka (Frank Adams) writes:
>In C++, one may instead write
>main() {
>	char *foo = "outer";
>	for (;; printf(foo),exit(0)) char *foo = "inner";
>}
>which should, in fact, print "inner"[1].  I don't currently have accesss to
>the C++ processor; does anyone know whether these two examples in fact work
>correctly for it?
>[1] Actually, my example may be an illegal multiple definition of foo.  In
>this case, try it with the "outer" declaration removed.

Or just move the outer declaration to outside the function; then it should
compile in any case.

On a related note -- after I apologized for posting that blooper in the first
place, I pointed out that the for-while equivalence SHOULD be written
    for (e1;e2;e3) s   -->   { e1; while (e2) { s e3; } }
with the outer braces necessary to make "if (e0) for (e1;e2;e3) s" have the
right semantics.  Given this, it seems to me that in the code fragment
    for (int i=0; i<N; ++i) f(i);
the variable "i" should go out of scope at the end of the "for".  Last I
heard (I don't have a C++ handy either), this was not the case.  Has this
been changed?

Even without the for-while equivalence, I think it's better to have the
variable go out of scope.  Otherwise why would it be declared as part of the
statement rather than in front of it?

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Technical Details
Message-ID: <165200003@haddock>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karl
References: <1793@mmintl.UUCP>

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!think!ima!haddock!karl
From: karl@haddock
Newsgroups: net.lang.c++
Subject: Re: for != while
Message-ID: <165200003@haddock>
Date: Thu, 18-Sep-86 20:24:00 EDT
Article-I.D.: haddock.165200003
Posted: Thu Sep 18 20:24:00 1986
Date-Received: Sat, 20-Sep-86 21:03:50 EDT
References: <1793@mmintl.UUCP>
Lines: 31
Nf-ID: #R:mmintl.UUCP:1793:haddock:165200003:000:1374
Nf-From: haddock!karl    Sep 18 20:24:00 1986