Help needed with #include problems

vlcek at mit-caf.UUCP vlcek at mit-caf.UUCP
Sat May 21 10:49:51 AEST 1988


People have been asking how to take care of external variables that
must appear in #include files; namely, how does one declare them in
the one file in which they are defined?

The answer I have seen so far is to use #defines to flag to the
#include file whether the current source file contains the variable
definition or merely an external reference.

Perhaps I am missing something, but this seems to me the wrong way to
do things.  For one thing, in a large application, one might need
quite a few #defines to take care of all of the external variables,
which may be interspersed through a number of #include files.  The
target of each #define would then have to be matched with its host
#include file, which the programmer would have to inspect to find out
initialization data, etc, etc.  Good heavens!

I am under the impression that there is nothing wrong with having an
``extern'' reference *and* a variable definition in the source file,
and in fact I have done so in all of my C programming.  So my #include
files contain only ``extern'' references; I declare (and initialize)
the variable in the proper source file, somewhere after the #include
statement.  Putting initialization data for a global variable into an
#include file seems to me almost an act of violence!
-- 
Jim Vlcek
vlcek at caf.mit.edu
!{ihnp4,harvard,seismo,rutgers}!mit-eddie!mit-caf!vlcek



More information about the Comp.lang.c mailing list