🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Alex L. Bangs Thu, 23 Nov 1995 00:13
variable scope warnings
#2667
Author: 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. ]
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