Path: utzoo!attcan!uunet!unhd!al From: al@uunet!unhd (Anthony Lapadula) Newsgroups: comp.lang.c Subject: Modifying Typedefs (And Implementing Them) Message-ID: <1990Sep14.213822.4828@uunet!unhd> Date: 14 Sep 90 21:38:22 GMT Distribution: na Organization: Computing Information Services, University of New Hampshire Lines: 44 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@unh.edu) Lapadula // Wanted: catchy .sig.