🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2052

Re: Scope of variables declared in if/while/for

#2052
From: rjl
Date: Wed, 27 Sep 1995 17:40
31 lines
1835 bytes
In article <MATT.95Sep25095657@physics2.berkeley.edu> you write:
>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.

Yes, it sure does.  However this was first talked about back when the
ARM was written.  Good compilers will let you do both.  Here's what
gcc-2.7.1 will do for your code snippet -

(Default options)
xx.cc: In function `int main()':
xx.cc:6: warning: name lookup of `i' changed for new ANSI `for' scoping
xx.cc:1: warning:   using obsolete binding at `i'

(-ansi -pedantic -ffor-scope)
xx.cc: In function `int main()':
xx.cc:6: `i' undeclared (first use this function)
xx.cc:6: (Each undeclared identifier is reported only once
xx.cc:6: for each function it appears in.)

Regards,
	Rohan
-- 
----------------------------------------------------------------------------
rjl@iassf.easams.com.au	| All quotes can be attributed to my automated quote
Rohan Lenard            | writing tool.  Yours for just $19.95; and if you
+61-2-367-4555          | call now you'll get a free set of steak knives ...
---
[ 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: <199509270658.AA06001@hercules.iassf.easams.com.au>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 27 Sep 95 17:40:05 GMT
Approved: fjh@cs.mu.oz.au
From: rjl@iassf.easams.com.au
Message-ID: <199509270658.AA06001@hercules.iassf.easams.com.au>
X-Original-Date: Wed, 27 Sep 1995 16:58:51 +1000
Subject: Re: Scope of variables declared in if/while/for
Newsgroups: comp.std.c++
In-Reply-To: <MATT.95Sep25095657@physics2.berkeley.edu>
Organization: EASAMS (Australia) Pty Ltd
Cc: std-c++@ncar.ucar.edu