Interpretation of peculiar declarators?

Norman Diamond diamond at jit533.swstokyo.dec.com
Wed May 8 10:05:45 AEST 1991


In article <679 at rosie.NeXT.COM> mself at next.com writes:

>	typedef int t;
>	void foo (void)	{ t t, x; }
>I believe this ought to declare t and x to be of type int,

I believe that the BNF constructions cause this result.

>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).

This seems true too, for the reasons you gave (and I deleted).

>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.

Sorry to be pedantic, but the compiler only has to behave "as if" it were
doing this.  Out of curiosity, what else would you want to do?  Would you
prefer for the result to be undefined?  Maybe this causes a bit of extra
work in implementing an incremental compiler, but surely there is no other
meaningful result.

>Can anyone clear this up?

I'd say you cleared this up yourself, mself.
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.



More information about the Comp.std.c mailing list