🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1020

multiple definitions of identifiers with external linkage

#1020
From: Paul Eggert
Date: Tue, 28 Nov 1989 02:30
41 lines
2250 bytes
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.
Technical Details
Message-ID: <57@looney.twinsun.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucla-cs!twinsun!eggert
References: <11193@riks.csl.sony.co.jp> <11693@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucla-cs!twinsun!eggert
From: eggert@twinsun.com (Paul Eggert)
Newsgroups: comp.std.c
Subject: multiple definitions of identifiers with external linkage
Message-ID: <57@looney.twinsun.com>
Date: 28 Nov 89 02:30:31 GMT
References: <11193@riks.csl.sony.co.jp> <11693@smoke.BRL.MIL>
Sender: news@twinsun.com
Reply-To: eggert@twinsun.com (Paul Eggert)
Organization: Twin Sun, Inc
Lines: 41