🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Herb Sutter Mon, 25 Sep 1995 22:18
Re: Scope of variables declared in if/while/for
#2036
Author: Herb Sutter
Date: Mon, 25 Sep 1995 22:18
29 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads