typedef + extern

Henry Spencer henry at zoo.toronto.edu
Wed Aug 22 04:07:02 AEST 1990


In article <1990Aug21.083324.13542 at santra.uucp> sja at 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 at zoo.toronto.edu   utzoo!henry



More information about the Comp.std.c mailing list