[comp.std.c] typedef + extern

sja@sirius.hut.fi (Sakari Jalovaara) (08/21/90)

Speaking of nits, how about this:

	typedef int x;

	void f () { extern int x; x = 5; }

Is the second declaration of "x" legal?

If it is, what linkage does "x" have?  3.1.2.2 would suggest that the
second declaration "has the same linkage as any visible declaration of
the identifier with file scope" -- i.e. none?
									++sja

henry@zoo.toronto.edu (Henry Spencer) (08/22/90)

In article <1990Aug21.083324.13542@santra.uucp> sja@sirius.hut.fi (Sakari Jalovaara) writes:
>	typedef int x;
>
>	void f () { extern int x; x = 5; }
>
>Is the second declaration of "x" legal?

Unfortunately, yes, although you cannot use `extern x;' as shorthand for
it -- that means something entirely different!  As K&R1 said:  "It is
agreed that the ice is thin here."

In my experimental C parser, the line that handles this is commented:
"The Syntax From The Black Lagoon".  It is really painful to have to
feed scope information back to the scanner so it can decide whether a
given identifier is a type name or not.  Bad enough that it has to
make the decision in the first place...

>If it is, what linkage does "x" have?  3.1.2.2 would suggest that the
>second declaration "has the same linkage as any visible declaration of
>the identifier with file scope" -- i.e. none?

Methinks this qualifies as a slight oversight in the wording. :-)
-- 
Committees do harm merely by existing. | Henry Spencer at U of Toronto Zoology
                       -Freeman Dyson  |  henry@zoo.toronto.edu   utzoo!henry