Help needed with #include problems
Lloyd Zusman
ljz at fxgrp.UUCP
Sat May 21 03:37:57 AEST 1988
In article <2955 at ihlpe.ATT.COM> dcon at ihlpe.UUCP (David Connet) writes:
> ...
> Here is a method I often use ...
> ...
> 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
> #define INIT(x) = x
> #else
> #define EXTERN extern
> #define INIT(x)
> #endif
>
> EXTERN int variable INIT(2);
Here's a slight variation that I use:
#ifdef GLOBAL
#define _ , /* allows you to init multilple values ... see below */
#define EXTERN
#define INIT(x) = { x } /* note the braces */
#else
#define EXTERN extern
#define INIT(x)
#endif
EXTERN int variable INIT(2);
EXTERN int array[] INIT( 1 _ 2 _ 3 _ 4 ); /* this works! */
I saw this on the net a year or two ago.
More information about the Comp.lang.c
mailing list