Path: utzoo!mnetor!uunet!husc6!uwvax!oddjob!ncar!ames!amdahl!dlb!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: global data in C programming... Message-ID: <343@soleil.megatest.UUCP> Date: 21 Mar 88 22:00:37 GMT References: <12471@brl-adm.ARPA> Organization: Megatest Corporation, San Jose, Ca Lines: 31 in article <12471@brl-adm.ARPA>, PEPRBV%CFAAMP.BITNET@husc6.harvard.EDU (Bob Babcock) says: > >>>how does one use global data in C programming? > > Basically, the global variables should be declared with the extern > keyword in every source file but one. (Note that this is really > a linker requirement; I'm not sure whether all environments require > this.) The way I do this is in the include file, I put > EXTERN int x,y; > in main (before the file is included) I put > #define EXTERN > and in all other routines I put > #define EXTERN extern > If the global variable is explicitly initialized, you need to put in > #ifdef's of some sort so that the initialization is only done where the > extern keyword is absent. Are you aware of the organization SLMA? I thought not. Before you spend another anguished night, please contact your local chapter of Silly Little Macros Anonymous. You owe it to yourself, to your code, and to generations of code-maintainers to come. It's only the first step, but a step you will never regret. This is something you should not have to face by yourself. One line at a time, Dave J.