Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!lll-winken!ubvax!ardent!peck!rap From: rap@peck.ardent.com (Rob Peck) Newsgroups: comp.sys.amiga.tech Subject: Re: Lattice and externals Message-ID: <9253@ardent.UUCP> Date: 14 Nov 89 17:43:22 GMT References: <704@crash.cts.com> Sender: news@ardent.UUCP Reply-To: rap@peck.ardent.com (Rob Peck) Organization: Ardent Computer Corp., Sunnyvale, CA Lines: 28 In article <704@crash.cts.com> wade@pnet01.cts.com (Wade Bickel) writes: > I'm using Lattice C and have declared a pointer with the same name in two >seperate modules. Neither has the "extern" keyword in front of it, and I'd >like each to be local to its own module (soon almost all of my modules will >need such a pointer, and I'd like to avoid naming confusion). > When I link the program blink barfs on a "symbol redefined" error. Should >this be happening? In C, any variable name declared in global space becomes a global variable, with or without the "extern" keyword defined. The primary purpose for using an extern is to tell the compiler that a particular label or function call returns a specific kind of value. If the compiler sees a reference to something and it has not yet seen a type declaration for it, the compiler assumes that the items is, or returns, an integer value (depending on whatever the size of an int is, 16 or 32 bits). By declaring something with "extern", you also specify its type, therefore giving the compiler the information that it needs to handle the object locally in this single module compile. When you finally link everything together, think of your complete set of modules as though they were written as part of a single complete source program, passed through the compiler as though all modules were typed one after another. The linker, at link time, must assign a unique address value (or stack offset value for automatic... local variables) to each symbol. Because you have used the same (global) symbol more than once, it correctly tells you that there has been a symbol redefinition, and cannot resolve the symbol references to a single location. Rob Peck