🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by rjl Wed, 27 Sep 1995 17:40
Re: Scope of variables declared in if/while/for
#2052
Author: 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. ]
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