Interpretation of peculiar declarators?

mself at next.com mself at next.com
Wed May 8 05:11:44 AEST 1991


I am trying to determine whether the following program is in error:

	typedef int t;

	void foo (void)
	{
	  t t, x;
	}

I believe this ought to declare t and x to be of type int, since I don't  
believe that the fact that t is re-declared as a variable instead of a typedef  
in the first declarator should affect the interpretation of the identifier t in  
the type-specifier for the second declarator (since the type-specifier is  
lexcically before the redefinition).  That is, I do not believe that

	t t, x;

is equivalent to

	t t;
	t x;

ANSI is quite specific that the scope of an identifier begins "just after the  
completion of its declarator" (3.1.2.1), and there is nothing to indicate that  
the identifiers in the type-specifier may be re-interpreted at each declarator.

An even more complicated case is this:

	t t = 1, x = t;

In this case I believe that this is exactly equivalent to

	int t = 1, x = t;

That is, it declares t and x to be of type int, and initializes x to the  
current value of t (which is 1).

If all of this speculation is true, then it puts some fairly strong constraints  
on the implementation of compilers.  A compiler must look up any type name in  
the type-specifier only once (before processing any of the declarators), and it  
must enter the newly declared identifiers into the symbol table before  
processing subsequent declarators.

Can anyone clear this up?



More information about the Comp.std.c mailing list