🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#2059
From: Michael Cook
Date: Wed, 27 Sep 1995 14:48
26 lines
1691 bytes
>>>>> "MA" == Matt Austern <matt@godzilla.EECS.Berkeley.EDU> writes:

 MA> Just about the only good news is that most programs will break
 MA> noisily: it's only when you're already playing dangerous games with
 MA> variables of the same name in different scopes that a legal program
 MA> that does one thing will turn into a legal program that does something
 MA> else.

A quality compiler would offer a warning about code like this:

  int i;
  // ...
  {
    for (int i = 0; i < 10; i++)
      f(i);
    g(i); // warning: which instance of `i' did you mean?
  }

because the code has two (entirely different) valid meanings depending on
whether your compiler is up to date.

Michael.

[ 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: <r4splivdke.fsf@erawan.cognex.com>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <MATT.95Sep25095657@physics2.Berkeley.EDU> <MATT.95Sep25110939@godzilla.EECS.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: Michael Cook <mcook@cognex.com>
Newsgroups: comp.std.c++
Subject: Re: Scope of variables declared in if/while/for
Date: 27 Sep 1995 14:48:39 GMT
Organization: Cognex Corporation, Natick, Massachusetts
Sender: mcook@cognex.com
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <r4splivdke.fsf@erawan.cognex.com>
References: <MATT.95Sep25095657@physics2.Berkeley.EDU>
        <MATT.95Sep25110939@godzilla.EECS.Berkeley.EDU>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: erawan.cognex.com
In-Reply-To: matt@godzilla.EECS.Berkeley.EDU's message of 25 Sep 95 20:43:14 GMT
X-Newsreader: Gnus v5.0.2
Content-Length: 687
X-Lines: 22
Originator: clamage@taumet