Topic: Scope rules in new ANSI for lookup


Author: Tiaan Wessels <tiaan@inetsys.alt.za>
Date: 1996/01/18
Raw View
Can someone please enlighten me on the new ANSI 'for' scoping's name
lookup rules. A lot of my code seems not to work when compiled with a
compiler ( gcc.2.7.x ) that implements this.

--
Tiaan Wessels
tiaan@inetsys.alt.za
Netsys International
---
[ 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. ]





Author: Alun.Champion@bridge.bst.bls.com (Alun Champion)
Date: 1996/01/18
Raw View
In article <30FE0827.52A0C2CF@inetsys.alt.za> Tiaan Wessels <tiaan@inetsys.alt.za> writes:

: Can someone please enlighten me on the new ANSI 'for' scoping's name
: lookup rules. A lot of my code seems not to work when compiled with a
: compiler ( gcc.2.7.x ) that implements this.

Sure.

6.5.3 The for statement
...
 4 If the for-init-statement is a declaration, the scope of the name(s)
   declared extends to the end of the for-statement. [Example:
 int i = 42;
 int a[10];

 for (int i = 0; i < 10; i++)
     a[i] = i;

  int j = i; // j = 42
   -end example]
...

Regards

   -A.
--
| A.Champion                |
---
[ 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. ]