Topic: variable scope warnings
Author: bangs@netcom.com (Alex L. Bangs)
Date: 1995/11/23 Raw View
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. ]