🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

variable scope warnings

#2667
From: Alex L. Bangs
Date: Thu, 23 Nov 1995 00:13
38 lines
1790 bytes
One of my peeves about C++ is when I accidentally define a variable a
second time within the same function, usually from copying some code
around and then forgetting it. I've been running into this more now that I
am using C++'s ability to declare vars anywhere in a function instead of
all at the start.

For example:

void func(void)
{
  int x;

  {
      int x;
  }
}

I realize that this is legal in C, and therefore C++ allows it as well.
While people can argue about whether it is good practice or not, it
probably has to remain a feature of the language for backward
compatibility.

My question is whether it would be possible for the standard to specify
that a C++ compiler should provide an option to warn the user if this is
encountered. Is there a precedent for specifying compiler warnings as part
of the standard? Is this a good idea or is it a way for vendors to
differentiate their offerings?

Thanks,
Alex

-- 
Alex L. Bangs
bangs@netcom.com
---
[ 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: <bangs-2211951505580001@bangs.slip.netcom.com>
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back
From: bangs@netcom.com (Alex L. Bangs)
Subject: variable scope warnings
Message-ID: <bangs-2211951505580001@bangs.slip.netcom.com>
Originator: fjh@munta.cs.mu.OZ.AU
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Earth2, New Pacifica Station
X-Original-Date: Wed, 22 Nov 1995 23: 04:17 GMT
Date: Thu, 23 Nov 1995 00:13:35 GMT
Approved: fjh@cs.mu.oz.au
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMLO81OEDnX0m9pzZAQGLlAF/Z7dNotGgYqmDG3Jvup9lQIEiub+76P4E
 a1W8j847ZgUdAZe2bgSh6urBjvSGrlvS
 =56Op