multiple definitions of identifiers with external linkage

Paul Eggert eggert at twinsun.com
Tue Nov 28 13:30:31 AEST 1989


Norman Diamond writes:

	... the standard does not limit an identifier with external linkage to
	having only one initialization (when the identifier is never used in an
	expression).

Doug Gwyn replies:

	... I have not been convinced that the Standard has a problem in this
	area.  Section 2.1.2 makes the initialization model pretty clear, and
	combined with the obvious notion that a variable holds a single value
	at a time it precludes multiple simultaneous initializers.

2.1.2 (Execution environments) does not really resolve this issue because 2.1.2
doesn't have to be combined with the ``obvious notion''.  2.1.2 says:

	All objects in static storage shall be _initialized_ (set to their
	initial values) before program startup.  The manner and timing of such
	initialization are otherwise unspecified.

It's reasonable to interpret this to mean that multiple initial values are
allowed, and that the multiple initializations are performed, but that because
the manner and timing of initialization is unspecified, the ``winning'' initial
value is unspecified.

Besides, 2.1.2 is a red herring here.  The real problem is a bug in the wording
in 3.7 (External definitions).  This bug applies to both objects and functions,
so it also permits multiple definitions of unused functions with external
linkage.  HP's Walter Murray pointed this out in a news posting, as did Twin
Sun's Mike Coleman when he originally brought this problem to my attention.
Thus, the following program is strictly conforming even though it's
``obviously'' wrong:

	int F(){return 0;}
	int F(){return 1;}
	int V = 0;
	int V = 1;
	int main(){return 0;}

Even assuming that the above quote from 2.1.2 prohibited the two Vs,
it wouldn't address the problem of the two Fs.



More information about the Comp.std.c mailing list