Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!sun-barr!rutgers!mjm!mjf From: mjf@mjm.mjm.com (Mark Fresolone) Newsgroups: comp.lang.c Subject: Re: Correct or Not or Old-fashioned or Bug Message-ID: <1300001@mjm.mjm.com> Date: 21 May 91 22:32:53 GMT References: Organization: Melillo Consulting, Somerset, NJ Lines: 48 > grimlok@hubcap.clemson.edu (Mike Percy) >grogers@convex.com (Geoffrey Rogers) writes: >>In article zhoumi@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 ... ------ appication.c -------- #include .... 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@mjm.com, rutgers!mjm!mjf Melillo Consulting/MJM Software 908-873-0620/Fax 908-873-2250