global data in C programming...

Bob Babcock PEPRBV%CFAAMP.BITNET at husc6.harvard.EDU
Fri Mar 18 04:48:43 AEST 1988


>>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.



More information about the Comp.lang.c mailing list