ANSI typedef rules

Mike Sangrey mike at sojurn.UUCP
Mon Mar 25 05:28:40 AEST 1991


In article <1991Mar16.233150.4078 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <793 at llnl.LLNL.GOV> rjshaw at ramius.llnl.gov (Robert Shaw) writes:
>>In regards to ANSI C, what (if anything) does the standard say about 
>>an identifer that is in the scope of both a typedef and a variable 
>>declaration by the same name?
>
>There is no such thing.  Only one of the two will be visible at any
>given place.  Taking your example:
>
>>typedef int thing;
>>  {
>>    thing t2;
>>    int   thing;
>>    thing t3;        /** (2) breaks **/
>
>The declaration of `thing' as an int variable hides the declaration as
>a type name in the outer scope.  From the semicolon ending `int thing;'
>until the closing brace, `thing' is the name of a variable, not a type.

I'm new around these net parts, but I think the answer is incorrect -- correct
me if I'm wrong -- I'm sure someone will ;-)  

The following is from X3J11/88-159 -- December '88 draft.  Sorry, don't
have the latest.

"A typedef name shares the same name space as other identifiers declared
in ordinary declarators.  If the identifier is redeclared in an inner
scope or is declared as a member of a structure or union in the same or
an inner scope, the type specifiers shall *not* be omitted in the inner
declaration." (emphasis mine)

Seems to me that 

typedef int stuff;
stuff stuff;

is fine.  Kinda confusing, but perfectly valid.

Mike @ The Sojournage Palace     "It muddles me rather." Winnie the Pooh.
rutgers!sci!devon!sojurn!mike



More information about the Comp.lang.c mailing list