Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) Newsgroups: comp.lang.c Subject: Re: initializing Message-ID: <198@fxgrp.UUCP> Date: 15 Jan 88 18:58:11 GMT References: <11276@brl-adm.ARPA> Reply-To: fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software) Followup-To: <11276@brl-adm.ARPA> PEPRBV%CFAAMP.BITNET@husc6.harvard.EDU (Bob Babcock) Organization: FX Development Group, Inc., Mountain View, CA Lines: 37 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? This appeared on the net a couple years ago, I believe. Do the following: #define _ , /* i.e., define underscore to be comma */ #ifdef MAIN_PROGRAM #define INITIAL_VALUE(x) = {x} /* note the braces */ #else #define INITIAL_VALUE(x) #endif Then, int i INITIAL_VALUE(1); int j[8] INITIAL_VALUE(1 _ 2 _ 3 _ 4 _ 5 _ 6 _ 7 _ 8); Many purists will not like this, but if you want to do it, it should work. --- Lloyd Zusman Master Byte Software Los Gatos, California Internet: fxgrp!ljz@ames.arpa "We take things well in hand." UUCP: ...!ames!fxgrp!ljz