Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site itm.UUCP Path: utzoo!watmath!clyde!akgua!gatech!itm!danny From: danny@itm.UUCP (Danny) Newsgroups: net.unix-wizards Subject: Let ME try for a new topic... Message-ID: <182@itm.UUCP> Date: Wed, 30-May-84 16:23:22 EDT Article-I.D.: itm.182 Posted: Wed May 30 16:23:22 1984 Date-Received: Sat, 2-Jun-84 10:11:21 EDT Organization: In Touch - Atlanta, GA Lines: 44 Keywords: C, definition, reference, external [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)