Correct or Not or Old-fashioned or Bug
Mark Fresolone
mjf at mjm.mjm.com
Wed May 22 08:32:53 AEST 1991
> grimlok at hubcap.clemson.edu (Mike Percy)
>grogers at convex.com (Geoffrey Rogers) writes:
>>In article <ZHOUMI.91May20182038 at marlboro.nff.ncl.omron.co.jp> zhoumi at nff.ncl.omron.co.jp (Zhou Mi) writes:
>>>
>>One of the ways that I got around this problem of only having one file
>>with all of my externals is to do the following:
>>-------------- file 1 (pro_all.h) ----------------------
>>#ifndef EXTERN
>>#define EXTERN extern
>>#endif
>>EXTERN int i;
>>------------- file 2 (pro_main.c) ----------------------
>>#define EXTERN
[...]
>I've seen people do this kind of thing a lot, but I've never liked
>having to remeber to put #define EXTERN or some such in my code. I've
>found it easiest to confine my global data to two files:
>globals.h
> extern int foo;
[..] >and
>globals.c
> int foo;
[...]
>Comments?
I guess I use a hybrid of the two methods for public library data:
------ libName.h ------
#ifdef LIBName
int foo = FOO_DEFAULT;
double bar;
#else /* LIBName */
extern int foo;
extern double bar;
#endif /* else LIBName */
------ libNameinit.c -------
#define LIBName
#include <libName.h>
...
------ appication.c --------
#include <libName.h>
....
This allows me initialization (see FOO_DEFAULT above) which would be
awkward in the first method, and good maintainability, since the data
is defined and declared in the same file.
Mark Fresolone mjf at mjm.com, rutgers!mjm!mjf
Melillo Consulting/MJM Software 908-873-0620/Fax 908-873-2250
More information about the Comp.lang.c
mailing list