Article View: comp.sys.amiga.tech
Article #2130Re: Lattice and externals
From: Mike (I'll think of something ye...
Date: Tue, 14 Nov 1989 19:51
Date: Tue, 14 Nov 1989 19:51
38 lines
2508 bytes
2508 bytes
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? The answer is "it depends." Some C compilers allow you to have multiple definitions of a variable, which will get treated as one declaration at compile time. This behavior is not required by ANSI, but is mentioned as a common extension. Lattice doesn't support that extension. On the other hand, that behavior isn't what you want. You want the scope of the variable to be restricted to the file it's in. This is where the static keyword comes in. When applied to a definition outside of any function, it causes the defined object to have file scope. This applies to functions as well as variables, so that each modules private functions and variables can be made invisible to anything outside the file. Making all functions and variables that don't need linkage outside the file static is generally a good idea. Not only does it decrease name space polution for other modules, those objects have the internal name equivalence properties (31 significant characters, case-sensitive) instead of the external name equivalence propreties (6 characters, case-insensitive). Final note: don't confuse static outside of a function, which controls scope, with static inside of a function, which controls duration. <mike -- Come rain, come hail, come sleet, come snow Mike Meyer You don't like to drive to slow mwm@berkeley.edu You're always in the passing lane ucbvax!mwm It's enough to drive me out of my brain mwm@ucbjade.BITNET
Technical Details
Message-ID:
<1989Nov14.195151.15283@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!usc!apple!agate!eris.berkeley.edu!mwmReferences:
<704@crash.cts.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!usc!apple!agate!eris.berkeley.edu!mwm From: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) Newsgroups: comp.sys.amiga.tech Subject: Re: Lattice and externals Message-ID: <1989Nov14.195151.15283@agate.berkeley.edu> Date: 14 Nov 89 19:51:51 GMT References: <704@crash.cts.com> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer) Organization: Missionaria Phonibalonica Lines: 38