From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: 109fba,4873305131bf4d94 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public From: seebs@plethora.net (Peter Seebach) Subject: Re: Porting (was ADA and Pascal etc) Date: 1997/10/31 Message-ID: <63dddh$ih6$2@darla.visi.com>#1/1 X-Deja-AN: 286240111 References: <34557f2b.1934172@news.mindspring.com> <345AB871.413A@dynamite.com.au> <63d3sm$ap7$3@darla.visi.com> X-Complaints-To: news@visi.com X-Trace: darla.visi.com 878328049 18982 205.166.146.1 (31 Oct 1997 20:00:49 GMT) Organization: Plethora Internet Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-10-31T00:00:00+00:00 List-Id: In article , Matt Austern wrote: >The draft C++ standard is quite specific, and not at all random. If >you write > for (int i = 0; i < N; +i) { > // loop body > } >then the scope of the variable i does not extend past the end of the >loop. The same holds for while loops and if statements. Yes, but that's not what *used* to be C++. ARM p. 88 If the /for-init-statement/ is a declaration, the scope of the names declared extends to the end of the block enclosing the |for| statement. * There is no special scope rule for a name declared in the initializing statement in a /|for/| statement. This implies that the scope of such a name extends to the end of the block enclosing the /|for/| statement. For example, ... The absence of a special rule implies that the same name cannot be used to control two /|for/| loops in the same scope. ... On balance, it would probably have been better to introduce a special rule to limit the scope of a name introduced in the initializing statement of a /|for/| statement to the /|for/? statement, but much code now exists that dependss on the general rule. Now, what does this tell us? 1. C++, as of 1990, included something that was understood to be cruft, because there was existing code, already, depending on a poor decision. 2. It's okay to change this later, despite the existing code, including code written for a compiler you say is available *today*. >> C9X, of course, has the scope end with the end of the for; if you >> want i to scope beyond the for, declare it outside the for. >For C89 and C9X, the issue does not arise. Neither the C89 standard >nor the draft C9X standard allows variables to be declared in the >controlling expression of for, while, or if. Uhm. Which C9X draft are *YOU* looking at? The one *I* have sez that for's 'clause 1' can declare a statement, and further, gets the scope right without introducing a special rule. How do we do it? How is it that a bunch of lowly idiots unworthy to comprehend the glory that is C++ managed to get the scope right without a special scope rule? Easy! for() is declared to be equivalent, except for the behavior of continue, to { clause1; while (clause2) { statement; clause3; } } Poof! The scope is correct, and we have no special rule. And yes, we do have this in C9X. Good thing, IMHO; while I'm not a great fan of mixing declarations and code (it's necessary in C++ because constructors are expensive, So Sez The Book, but sort of pointless in C), but a thing which has no function but iterating should, indeed, be local to the loop iterating it. Please research your claims more before posting. I mean, it's really pretty bad for a C pusher to be able to quote the ARM at you. -s -- seebs@plethora.net -- Speaking for myself. No spam please. Copyright 1997. All rights reserved. This was not written by my cat. C/Unix wizard - send mail for help! -- - More Net, Less Spam!