Article View: comp.std.c++
Article #2886A (too) simple question about names
From: scott douglass
Date: Wed, 06 Dec 1995 16:04
Date: Wed, 06 Dec 1995 16:04
52 lines
2279 bytes
2279 bytes
First the context: I was trying to decide from the draft standard if the
following code is legal:
void f()
{
struct s { int s; };
typedef s x;
int x;
x = 5;
}
The question is whether 'typedef s x;' clashes with 'int x;'.
>From [Oct draft] section 3.3.7, Name hiding, we find:
2 A class name (_class.name_) or enumeration name (_dcl.enum_) can be
hidden by the name of an object, function, or enumerator declared in
the same scope. If a class or enumeration name and an object, func‚
tion, or enumerator are declared in the same scope (in any order) with
the same name, the class or enumeration name is hidden wherever the
object, function, or enumerator name is visible.
And in section 7.1.3, The typedef specifier, we find:
4 A typedef-name that names a class is a class-name (_class.name_).
Which seems to allow the above program.
But what if we change the typedef to, say, 'typedef long x;'? 'x' is no
longer a <class-name> so this is no longer allowed by 3.3.7.
So here's the real question: When can two <entities> in the same scope
have the same name?
"Everyone knows" that:
extern int f;
extern void f();
is ill-formed but where does the standard say it? I and some friends
looked through sections 3, 7 and 8 but we didn't find anything
satisfactory. [I admit it could still be hiding in there somewhere.]
Can you set me straight? Thanks,
--scott
[ 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:
<v02130511aceb19320bd6@[193.131.176.202]>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: sdouglass@armltd.co.uk (scott douglass) Newsgroups: comp.std.c++ Subject: A (too) simple question about names Date: 6 Dec 1995 16:04:02 GMT Organization: Sun Microsystems Inc., Mountain View, CA Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <v02130511aceb19320bd6@[193.131.176.202]> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Lines: 52 Content-Length: 1610 Originator: clamage@taumet