Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!tut.cis.ohio-state.edu!rutgers!att!ihlpb!nevin1 From: nevin1@ihlpb.ATT.COM (Liber) Newsgroups: comp.lang.c++ Subject: Re: Should C++ follow C's footsteps? Message-ID: <9773@ihlpb.ATT.COM> Date: 3 Mar 89 01:39:21 GMT References: <4800051@m.cs.uiuc.edu> <8902@alice.uucp> <2438@crete.cs.glasgow.ac.uk> Reply-To: nevin1@ihlpb.UUCP (55528-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 65 In article grunwald@flute.cs.uiuc.edu (Dirk Grunwald) writes: >Right now, you can't say: > > for (int i = 0; ....... etc ); > for (int i = 0; ....... etc ); > >because the C++ scope rules follow the C scope rules here. I'm not sure what you mean in this instance by "the C scope rules". Since C doesn't allow you to declare variables inside "for" statements, I assume you mean one of the following: a) You can't declare different types of variables within a "for" statement, because of the ambiguity problems with the semicolon. or b) Variables declared inside a "for" statement are visible to the end of the enclosing block, and not just within the "for" loop. (I think this is what you mean, and the following is my reply:) >I think this is >a major pain in the rear -- I try to restrict the scope of variables as >much as possible to reduce possible errors. Personally, I would also like to see the scope restricted to within the "for" loop. To get around this, I either 1) Declare the variable just outside the "for" loop (to emphasize the visibility past the end of the "for" loop): ... //some code int i; for (i=0; ...) ... //body of "for" loop 2) Put braces around the "for" loop (to limit the visibility of the control variable): ... //some code { for (int i=0; ...) ... //body of "for" loop } 3) Combine 1) and 2) (especially useful when declaring more than one variable while still trying to limit scope): ... //some code { int i; for (i=0; ...) ... //body of "for" loop } None of these are faults of C, however. -- _ __ NEVIN ":-)" LIBER nevin1@ihlpb.ATT.COM (312) 979-4751 IH 4F-410 ' ) ) "I will not be pushed, filed, stamped, indexed, / / _ , __o ____ briefed, debriefed or numbered! My life is my own!" / (_