Extern variables question

Will Crowder will at charyb.COM
Sat Nov 18 06:12:24 AEST 1989


In article <312 at charyb.COM> dan at charyb.UUCP (Dan Mick) writes:

>In article <89320.012957CMH117 at PSUVM.BITNET> CMH117 at PSUVM.BITNET (Charles Hannum) writes:
>>
>>[comment about defining global data in only one module, and declaring
>> it in the other modules used]
>
>Again:  What?
>
>Most PC linkers I've used will; but not Microsoft's, at least not with C 
>5.1, and *no* Unix linker I've ever heard of does.  That seems, to me, to
>be one of the huge implementation-philosophy differences between Unix-oid
>C and PC-oid C.
>-- 
>.sig files are idiotic and wasteful.

Why the "What?", Dan?  The man's answer was good advice as far as I'm
concerned.  I prefer the PC-oid style.  It just seems to make sense that 
since you're defining storage for one location, you define it in one place.  
You can declare its existence wherever you want to use it.  This actually 
seems useful to me, since that way you can know that once you've found the 
definition of the variable you aren't using, you can remove it *in once 
place* and it's gone.  Other modules which used it will get complaints.  
Further, the PC-oid style encourages the concept of an object module 
"owning" a data object.  If indeed it is not appropriate for any single 
executable code module to own the data object, because it's used equally 
everywhere, then you can have a "global data" module which only defines 
the global data.  Again, the scope and ownership of the data object
is defined in the source module.

Also, the PC-oid style encourages (read: requires) differentiation between 
the definition of an object (which reserves space), and the declaration 
of an object (which does not).  I consider this useful: one object,
one definition, multiple declarations of its existence in other source
modules which use it, and might depend on its proper initialization,
and which will cause complaints if the object doesn't exist at linktime.

Will



More information about the Comp.lang.c mailing list