Path: utzoo!attcan!uunet!mcvax!ukc!reading!cf-cm!cybaswan!iiit-sh From: iiit-sh@cybaswan.UUCP (Steve Hosgood) Newsgroups: comp.sys.ibm.pc Subject: MSC v4.0 Bug??. Summary: Global variable declarations broken? Keywords: declaration, C, extern Message-ID: <65@cybaswan.UUCP> Date: 31 Aug 88 14:23:54 GMT Reply-To: iiit-sh@cybaswan.UUCP (Steve Hosgood) Organization: Institute for Industrial Information Technology Lines: 48 References: I've got some routines in a library which make use of some references to global data. In a different file (also in the library) are all the declarations of this data. Here's an example: File 'fred.c' (yields object module 'fred'): extern int xxx; fred() { ........ xxx = 1; ....... } Data declaration file 'declare.c' (yields object module 'declare'): int xxx; .... .... After compilation (with MSC 4.0) the object files are linked (with MS Lib 3.04). The library is then used to resolve a call to routine 'fred'. Well, according to K&R, this *ought* to work. Object module 'fred' refers to the data (but doesn't declare it) using the extern statement. Object module 'declare' declares the variable 'xxx'. All should be happy. All UN*X systems I've seen have been happy with this. Not here! For this to work, the statements declaring the data in 'declare.c' actually have to *initialise* each declaration, otherwise they're not seen in the library. If I initialise all the variables explicitly to zero, all is well. I eventually discovered that this 'feature' is documented in an obscure way in the manual, though it took me over an hour to find it. This seems to be a fault to do with the library system, or the linker, as programs compile OK without having to initialise data when libraries arn't involved. Any comments? Thanks in advance, -----------------------------------------------+------------------------------ Steve Hosgood BSc, | Phone (+44) 792 295213 Image Processing and Systems Engineer, | Fax (+44) 792 295532 Institute for Industrial Information Techology,| Telex 48149 Innovation Centre, University of Wales, +------+ JANET: iiit-sh@uk.ac.swan.pyr Swansea SA2 8PP | UUCP: ..!ukc!cybaswan.UUCP!iiit-sh ----------------------------------------+------------------------------------- My views are not necessarily those of my employers!