🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2858

Interpretation of peculiar declarators?

#2858
From: mself
Date: Tue, 07 May 1991 19:11
44 lines
1790 bytes
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?
Technical Details
Message-ID: <679@rosie.NeXT.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!rosie!mself

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!rosie!mself
From: mself@next.com
Newsgroups: comp.std.c
Subject: Interpretation of peculiar declarators?
Message-ID: <679@rosie.NeXT.COM>
Date: 7 May 91 19:11:44 GMT
Sender: news@NeXT.COM
Lines: 44
Nntp-Posting-Host: kite.next.com
Originator: mself@kite