Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!iuvax!bobmon From: bobmon@iuvax.cs.indiana.edu (RAMontante) Newsgroups: comp.sys.ibm.pc Subject: Re: Possible Bug in Turbo Linker (and question about Turbo Debug) Message-ID: <14962@iuvax.cs.indiana.edu> Date: 13 Nov 88 17:33:55 GMT References: <1254@helios.ee.lbl.gov> Reply-To: bobmon@iuvax.UUCP (RAMontante) Organization: malkaryotic Lines: 48 (A better answer is probably to be had in comp.lang.c...) forrest@ux1.lbl.gov (Jon Forrest) writes: +I've been doing some playing around with Turbo C 2.0 and I have +found something that I didn't expect. This is the fact that +if you declare the same external variable in more than one file, +the linker treats them as separate variables instead of treating +them as references to the same variable. You can see this be +creating 2 files, each with "int x" as the first line. Compile +them and link them. You'll see an error message from the linker +saying "Error: x defined in module YYY is duplicated in module ZZZ" +(where YYY and ZZZ are the names of the files). Furthermore, if you +run OBJXREF /RC you see that "_x" exists in both object files +and uses space in both. [...] + +The reason I think this is wrong, in additon to being different +than the behavior on Unix and VMS, is that K&R (1st edition) +on page 206, section 11.1 says "... all references to the same +external identifier refer to the same object ...". [...] Looking at K&R sections 10 - 11.2, I conclude that Jon's definition of int x; in each file attempts to create an 'x' whose name is available to other files. Repeating the definition in other files does not create additional references to the same external identifier; rather that creates new externally-available variables with a single, conflicting name. In order for a file to _use_ an 'x' that was created/stored in another file, it must define extern int x; which says that the x *comes from* somewhere external to the file (i.e., another file). Consider this K&R quote, from section 11.2: "Thus in a multi-file program, an external data definition _without_ the extern specifier must appear in _exactly_one_ of the files. Any other files which wish to give an external definition for the identifier must include the extern in the definition." [Emphases mine] So Turbo is in agreement with K&R here, as well as the ANSI draft (I presume). -- -- bob,mon (bobmon@iuvax.cs.indiana.edu) -- "I thought it must be one of the prime numbers of the Zeeman Series. *I* haven't changed."