Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!fxgrp!ljz From: ljz@fxgrp.UUCP (Lloyd Zusman) Newsgroups: comp.lang.c Subject: Re: Help needed with #include problems Message-ID: <631@fxgrp.UUCP> Date: 20 May 88 17:37:57 GMT References: <28400001@ntvax> <6104@sigi.Colorado.EDU> <2955@ihlpe.ATT.COM> Reply-To: ljz%fx.com@ames.arc.nasa.gov (Lloyd Zusman) Organization: Master Byte Software, Los Gatos, California Lines: 39 In article <2955@ihlpe.ATT.COM> dcon@ihlpe.UUCP (David Connet) writes: > ... > Here is a method I often use ... > ... > In the main file I do: > > #define GLOBAL > #include "file.h" > #undef GLOBAL /* sometimes */ > > All other .c files just include file.h > > In file.h: > ... > #ifdef GLOBAL > #define EXTERN > #define INIT(x) = x > #else > #define EXTERN extern > #define INIT(x) > #endif > > EXTERN int variable INIT(2); Here's a slight variation that I use: #ifdef GLOBAL #define _ , /* allows you to init multilple values ... see below */ #define EXTERN #define INIT(x) = { x } /* note the braces */ #else #define EXTERN extern #define INIT(x) #endif EXTERN int variable INIT(2); EXTERN int array[] INIT( 1 _ 2 _ 3 _ 4 ); /* this works! */ I saw this on the net a year or two ago.