Help needed with #include problems

452is-Connet dcon at ihlpe.ATT.COM
Thu May 19 23:34:16 AEST 1988


Several people have commented on the fact of extern...

Here is a method I often use (this was also discussed some
months back).  [I tried to mail it to you, but the mail bounced.)

In the main file I do:

#define GLOBAL
#include "file.h"
#undef GLOBAL /* sometimes */

All other .c files just include file.h

In file.h:

#ifdef GLOBAL
#define EXTERN
#else
#define EXTERN extern
#endif

EXTERN int variable;
(etc)

Now I can have all my variables in one place.
Of course, if you need to initialize variables, that
throws another wrench in the works, but one that can
be handled by the same method.

#ifdef GLOBAL
#define EXTERN
#define INIT(x) = x
#else
#define EXTERN extern
#define INIT(x)
#endif

EXTERN int variable INIT(2);

Hope this helps some (and doesn't open too big a can of worms here!)

Dave Connet
ihnp4!ihlpe!dcon



More information about the Comp.lang.c mailing list