Xref: utzoo comp.sys.ibm.pc:21038 comp.lang.c:13920 Path: utzoo!utgpu!watmath!clyde!mcdchg!chinet!att!osu-cis!tut.cis.ohio-state.edu!cwjcc!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon S. Allbery) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: MSC multiple-definition bug or feature? Message-ID: <12861@ncoast.UUCP> Date: 29 Oct 88 17:06:34 GMT References: <6215@bunny.UUCP> <1099@dutinfd.UUCP> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.sys.ibm.pc Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 50 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 ncoast!allbery@hal.cwru.edu allbery@skybridge.sdi.cwru.edu 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@.