MSC multiple-definition bug or feature?
Brandon S. Allbery
allbery at ncoast.UUCP
Sun Oct 30 03:06:34 AEST 1988
As quoted from <1099 at dutinfd.UUCP> by oosten at dutinfd.UUCP (Gertjan van Oosten):
+---------------
| In article <6215 at bunny.UUCP>, rhb6 at bunny.UUCP (Robert H. Barkan) writes:
| > In MSC 5.x, compile the following 2 files, then link x1.obj and y1.obj.
| > The linker should complain because "int x" is multiply defined:
|
| In one C file, I had the following (external) declaration:
| static int x;
|
| In another C file, I had:
| extern int x;
|
| Compilation and linkage produced no "Unresolved external" message!!!!!
| How nice of Microsoft....
|
| I also tried this on four other machines. Here come the results, fasten
| seatbelts and refrain from smoking:
| A 3B1 running System V version 3.5:
| No linker error message; however, lint complains about "Used but not
| defined".
| A Microdutch running System V Release 2 X/OPEN:
| No linker error message; however, lint complains about "Used but not
| defined".
| A VAX running 4.3 BSD:
| Linker produces error message; lint complains.
| A PDP-11/73 running ULTRIX-11:
| !!!Linker produces error message; lint DOESN'T complain!!!
|
| So only 4.3 BSD functions correctly; that's ONE out of FIVE!!!
| Enough said...
+---------------
But did you try to run it and see which "x" was in use?
In K&R C, the default storage class of a variable declared outside a function
is "extern". The corollary is that the "extern" declaration serves both as
reference and as linker definition, i.e. the "extern int x" is a different
variable from the "static int x". If they have the same address, however,
the linker is broken. Note also that K&R C isn't followed all that closely
by many compilers in this respect; they instead have the default storage
class as a sort of "invisible" storage class which acts as reference and
definition, while "extern" is merely reference.
++Brandon
--
Brandon S. Allbery, comp.sources.misc moderator and one admin of ncoast PA UN*X
uunet!hal.cwru.edu!ncoast!allbery <PREFERRED!> ncoast!allbery at hal.cwru.edu
allbery at skybridge.sdi.cwru.edu <ALSO> allbery at uunet.uu.net
comp.sources.misc is moving off ncoast -- please do NOT send submissions direct
Send comp.sources.misc submissions to comp-sources-misc@<backbone>.
More information about the Comp.lang.c
mailing list