home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!netcomsv!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c
- Subject: Re: initialized extern variables, coded in 1 file, used in many
- Message-ID: <926@ulogic.UUCP>
- Date: 27 Jan 93 18:53:42 GMT
- References: <1993Jan26.015543.23671@netcom.com>
- Organization: negligable
- Lines: 64
-
- In article <1993Jan26.015543.23671@netcom.com> pdh@netcom.com (Phil Howard ) writes:
- >I want to define a large set of extern variables and I want to define
- >them in just one place (one file) so that I don't have any problems
- >with things out of sync as I change them (changes of type for existing
- >variables, or adding and deleting variables).
- >
- >For the above would create variables in a header like:
- >
- >EXTERN long var1;
- >EXTERN int var2;
- >
- >and do
- >
- >#define EXTERN extern
- >
- >in all files but the one where they are being exported from. In that
- >one file I would do
- >
- >#define EXTERN
-
- Rather than this, which requires an extra #define in every file
- I prefer to put this in the globals.h include file:
-
- #ifdef __MAIN
- #define EXTERN
- #else
- #define EXTERN extern
- #endif
-
- and place a "#define __MAIN" in one of my files prior to including
- the globals.h.
-
- >and include the header before the first block. The choice of symbol
- >name EXTERN is arbitrary; some other name may be used if consistent.
- >
- >---------------- NOW HERE IS THE CATCH ----------------
- >
- >I want to initialize many (its ok to be required to initialize all)
- >of these variables. The problem is that initializers are inconsistent
- >with the extern storage class. But the initializers would have to be
- >coded in the same file as the types of the variables are coded, i.e.
- >the header. That means the initializers would be there for those modules
- >using the variables with the extern class.
-
- EXTERN int uninitialized;
-
- #ifdef EXTERN
- extern int initialized1;
- extern float initialized2;
- extern int initialzed3[];
- #else
- int initialized1 = 50;
- float initialized2 = 3.14;
- int initialzed3[] = { 2, 4, 6 };
- #endif
-
-
-
- -Richard Hartman
- hartman@ulogic.COM
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- "Who knows what evil lurks in the hearts of men?"
-
-