iiit-sh@cybaswan.UUCP (Steve Hosgood) (08/31/88)
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!