Article View: comp.std.c++
Article #2036Re: Scope of variables declared in if/while/for
From: Herb Sutter
Date: Mon, 25 Sep 1995 22:18
Date: Mon, 25 Sep 1995 22:18
29 lines
1920 bytes
1920 bytes
In article <MATT.95Sep25095657@physics2.Berkeley.EDU>, rmartin@rcmcon.com (Robert Martin) wrote: >In reading the WP I see that the scope of variables declared in 'for' >statements is now identical with the scope of variables declared in >'if' and 'while' statements. i.e. any variable declared in a 'for', >'if' or 'while' statement is local to the statement, and to the >controlled statement, but not to the enclosing scope. <snip> >Do I have this right? If so, doesn't this break a lot of old C++ >programs that depended upon variables declared in the 'for' statement >being local to the enclosing scope. Sounds right. This was covered a few months ago in the June CUJ, Dan Saks' column. It may indeed break code that relies on the old rule, but as Saks points out the new rule is finally more consistent and stamps out some annoying surprises that used to be legal (e.g. you could have the lifetime and scope of an object not end at the same time, and then there was some weirdness introduced by the RTTI rules). Herb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Herb Sutter 2228 Urwin, Ste 102 voice (416) 618-0184 Connected Object Solutions Oakville ON Canada L6L 2T2 fax (905) 847-6019 --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<199509252101.RAA16547@gold.interlog.com>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 25 Sep 95 22:18:46 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Message-ID: <199509252101.RAA16547@gold.interlog.com> From: herbs@interlog.com (Herb Sutter) Subject: Re: Scope of variables declared in if/while/for Organization: Connected Object Solutions (div of Daystar Software Systems Design Inc.) X-Original-Date: Mon, 25 Sep 95 21:06:34 GMT