Forward Referencing of Static Variables OK?

Doug Pardee doug at terak.UUCP
Sat Oct 5 03:14:14 AEST 1985


>From K&R Appendix A:
  11.2 Scope of externals
   If a function refers to an identifier declared to be extern then
   somewhere... there must be an external [as opposed to static -- dlp]
   definition for the identifier.
   ...
   The appearance of the extern keyword in an external definition
   indicates that storage for the identifiers being declared will be
   allocated in another [as opposed to the current -- dlp] file.

 11.1 Lexical scope
   The lexical scope of identifiers declared in external definitions
   persists from the definition through the end of the source file in
   which they appear.

The problem here is that an "extern" declaration tells the compiler that
the address for the data item (or function) will be supplied by the
link-editor when the program is linked; but the "static" declaration
tells the compiler that the address is "private information" to the
current module.

A system which is smart in this regard could provide a method for the
link-editor to be told that a given address is to be used only within
the current module.  But many systems aren't that "smart" -- it's only
useful for this one case.  A simpler approach is usually used: the
link-editor just isn't told about static variables.
-- 
Doug Pardee -- CalComp -- {calcom1,savax,seismo,decvax,ihnp4}!terak!doug



More information about the Comp.lang.c mailing list