oosten@dutinfd.UUCP (Gertjan van Oosten) (10/21/88)
In article <6215@bunny.UUCP>, rhb6@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: Then follows a description of some source, etc. leading to the exposure of a linker bug. I have another one for you: 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... G. J. van Oosten "When you come to me I'll question myself again Is this grip of life still my own?" - David Sylvian
seanf@sco.COM (Sean Fagan) (10/23/88)
In article <1099@dutinfd.UUCP> oosten@dutinfd.UUCP (Gertjan van Oosten) writes: |In article <6215@bunny.UUCP>, rhb6@bunny.UUCP (Robert H. Barkan) writes: |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: [says that only 4.3BSD works correctly.] Running XENIX, for the '386, Microsoft C Compiler (also '386), the linker complains bitterly. Also, lint ends up (quite nicely, I think) complaining that x is used but never defined in t1.c, and that x is defined but never used in t2.c (which is, of course, correct). So this means that Xenix is as good as 4.3 BSD? Glad *somebody* realized it 8-). -- Sean Eric Fagan | "ld runs like a turtle out of antartica" seanf@sco.UUCP | Steven Ryan (smryan@garth.UUCP) (408) 458-1422 | Any opinions expressed are my own, not my employers'.
allbery@ncoast.UUCP (Brandon S. Allbery) (10/30/88)
As quoted from <1099@dutinfd.UUCP> by oosten@dutinfd.UUCP (Gertjan van Oosten): +--------------- | In article <6215@bunny.UUCP>, rhb6@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@hal.cwru.edu allbery@skybridge.sdi.cwru.edu <ALSO> allbery@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>.