This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: typedef name question


Hi Michal,

John (Eljay) Love-Jensen wrote:
> You are allowed to introduce identifiers in a scope that
> shadow identifiers outside that scope.  Even in the
> "foo foo;" case, where you are using an outer scope
> identifier and in the process are introducing a new
> identifier that shadows that self-same outer
> scope identifier.

Just a small add-on:

In C++ you can easily test this rule and still access the outer identifier by explicitly looking it up in global namespace scope. The following compiles with g++:

// foo is defined in the global namespace
typedef int foo;

foo foo_fct(int a) {
   foo foo;              /* line 3: a variable foo with type foo */
   return (::foo)foo;    /* line 4: cast to outer foo */
}


Of course, this does not work with C.


Daniel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]