typedef bug summary

Jack Rouse jjr at sas.UUCP
Mon Jul 28 06:22:42 AEST 1986


The problem described by Tom Stockfisch, where a typedef identifier cannot be 
reused as a variable identifier in a nested scope is common to many C compilers
which use a formal grammar for parsing.  In order to handle ambiguities in the
C grammar, it is necessary for these compilers to regard typedef names and
normal identifiers as different lexical types.  Consider the following code:
	int i, bar;
	...
	i = (foo)&bar;
If foo is an int variable, the last statement performs a bitwise and of foo and
bar.  If foo is a typedef name (as in "typedef int foo;"), however, then the
last statement takes the address of bar and casts it to type foo.

To resolve this ambiguity, PCC derived compilers pass information back from the
parser to the lexical scanner when a typedef name is created so that it will
not be treated as a regular identifier.  What PCC has neglected to do, however,
is provide a means to redeclare the name in a inner scope.
-- 
--
Jack Rouse, SAS Institute Inc., Box 8000, Cary, NC 27511  USA
USENET:  mcnc!rti-sel!sas!jjr          TELCO :  (919) 467-8000



More information about the Comp.lang.c mailing list