Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!cbosgd!ihnp4!laidbak!daveb From: daveb@laidbak.UUCP (Dave Burton) Newsgroups: comp.lang.c Subject: Re: initializing Message-ID: <1313@laidbak.UUCP> Date: 19 Jan 88 02:19:21 GMT References: <11276@brl-adm.ARPA> Reply-To: daveb@laidbak.UUCP (Dave Burton) Organization: is pretty bad/My method of Lines: 34 In article <11276@brl-adm.ARPA> PEPRBV%CFAAMP.BITNET@husc6.harvard.EDU (Bob Babcock) writes: >If I want to initialize a global variable in an include file, and have >the initialization statement appear only in the main program, I can use >something like > > #ifdef MAIN_PROGRAM > #define INITIAL_VALUE(x) =x > #else > #define INITIAL_VALUE(x) > #endif > int i INITIAL_VALUE(1); > >But this doesn't work for an array, and I can't figure out anything >which does. Is there some trick I'm missing? I would consider this an abuse of conditional compilation. Conditionals are best used to control implementation of some implementation dependent code, not which module you're compiling. If the data is truly global (used throughout most of the modules in your code), consider using a file dedicated to initializing the globals. I have used a file named "global.c" for purposes such as this for years, with no ill effects. A separate data initialization file makes it easy to hunt down bad initializations. Do not place all globals in such a file, however. In the majority of cases, such variables are global to only one file. In this case they should be initialized at the top of that file, and declared static. -- --------------------"Well, it looked good when I wrote it"--------------------- Verbal: Dave Burton Net: ...!ihnp4!laidbak!daveb V-MAIL: (312) 505-9100 x325 USSnail: 1901 N. Naper Blvd. #include Naperville, IL 60540