Let ME try for a new topic...
Danny
danny at itm.UUCP
Thu May 31 06:23:22 AEST 1984
[ereh no gniog synnuf gnihtemos] (hold your terminal up to a mirror)
I recently discovered the first (to me, anyway) truly awkward
idiosyncrasy of C. I'm hoping to be enlightened by some
wizards (and, thereby, earn more brownie points toward becoming a
wizard myself) so that, in the future, I will have a clever out.
Now, on my (a Version 7) C compiler, there may be many
references to an external variable, but only one definition.
The logical place, when dealing with many source files, is to
put the definitions into the "main" (or, more succinctly, the
file that contains the function "main"), and put the references
into a .h file and whichever sources need the refs may include it.
Ok, so far. I've seen many programs that do this very thing.
But, this also creates the problem of having to update *two* files
every time an external is added, modified, or deleted. And, being
human (or in Spaf's case Vegan) it's easy to forget to update both.
I have seen the hack of preceding each reference with "extern", then
in "main" having a sequence of:
# define extern
# include "foo.h"
# undef extern
Well, it works, there is only one copy of each, everyone is happy,
except me. It looks like a hack, it feels like a hack. Is it possible
that it *is* a hack?
So, great wizards, humble yourselves, cast your eyes upon me, and
have great compassion. Remove from my eyes the smoke that blinds,
from my mind the spirits that slow, and from my back the frog that
causes warts.
Ok, so what's *your* favorite way to deal with this perennial
problem?
Sincerely, I thank you in advance,
Danny
--
Daniel S. Cox
(akgua!itm!danny)
More information about the Comp.unix.wizards
mailing list