Modifying Typedefs (And Implementing Them)

Anthony Lapadula al at uunet!unhd
Sat Sep 15 07:38:22 AEST 1990


While implementing a (hopefully soon-to-be-) ANSI-compliant compiler,
we came across the following problem.  Given

   typedef int  INT;
   typedef char CHAR;

which of the following are legal?

   main()
   {
       unsigned INT foo1;
       extern   INT foo2;
       extern   INT (CHAR);
   }

I've read section 3.5.6 of the standard, but with no luck deciding the issue.
Harbison and Steel (1987, p. 116) state that the declaration of ``foo1''
would be illegal, but the declaration of ``foo2'' would be legal.
This seems reasonable.

What about the third declaration?  Seems that it would declare a (new)
variable CHAR to be of type ``int'' and with storage class ``external''.
Is this right?  Is CHAR a candidate to be a variable because it may override
its typedef'ed meaning from the outer block?

It was discussed here (last month?) that implementing typedef-names is
done as follows: lexer get the candidate identifier, asks the symbol table
if it is currently a typedef-name, and returns, e.g., TYPEDEF or IDENTIFIER
to the grammar.

Doesn't the lexer have to know more?  In my third example, the
lexer needs to know that CHAR is a candidate variable, even though it
is currently a typedef-name.  How is this implemented?

As an aside, gcc 1.37.1 rejects my first example
   unsigned INT foo1;
but accepts
   INT unsigned foo1;

Any takers to explain this?

-- Anthony (uunet!unhd!al, al at unh.edu) Lapadula

// Wanted: catchy .sig.



More information about the Comp.lang.c mailing list