global data in C programming...

Dave Jones djones at megatest.UUCP
Tue Mar 22 08:00:37 AEST 1988


in article <12471 at brl-adm.ARPA>, PEPRBV%CFAAMP.BITNET at 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.



More information about the Comp.lang.c mailing list