🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by scott douglass Wed, 06 Dec 1995 16:04
A (too) simple question about names
#2886
Author: scott douglass
Date: Wed, 06 Dec 1995 16:04
52 lines
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. ]
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