Why can't you define an external object twice and never use it?

Paul Eggert eggert at rise.twinsun.com
Fri Nov 10 13:57:10 AEST 1989


The program

	int X = 0;
	int X = 0;
	main() { return 0; }

is ``obviously'' not ANSI C, but where does the proposed ANSI standard say so?
X has multiple external definitions with external linkage, but X is never used.

3.1.2.2 prohibits the same identifier from appearing with both internal and
external linkage.  3.5's constraints prohibit multiple declarations of
identifiers with no linkage, and also prohibit declarations in the same scope
that refer to the same object but specify incompatible types.  3.7's
constraints prohibit multiple external definitions with internal linkage.
3.7's semantics prohibit multiple external definitions of any identifier that
is declared with external linkage and used in an expression.

However, none of these prohibitions apply to the above program.  What's wrong?



More information about the Comp.std.c mailing list