Path: chuka.playstation.co.uk!news From: Philip Gooch Newsgroups: scee.yaroze.beginners Subject: Re: Object files and linking Date: Sun, 19 Jul 1998 02:13:21 +0100 Organization: philg@nospam.easynet.co.uk Lines: 46 Message-ID: <35B1482F.94AB6660@nospam.easynet.co.uk> References: <35AE6952.2D94C5E9@scee.sony.co.uk> <35AF91D1.CCE4F782@compuserve.com> <35AFB921.F692044A@scee.sony.co.uk> Reply-To: philg@nospam.easynet.co.uk NNTP-Posting-Host: philg.easynet.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 (Macintosh; I; PPC) James Russell wrote: > Nick Slaven wrote: > > > > It might be worth mentioning pre processor directives (I think thats the name). > > I use them in a similar way: > > If I've got Graphics.c which has globals that must be accessed by other modules, I do this: > > Graphics.c: > #define _GRAPHICS_C > #include "graphics.h" > ... > yadda yadda yadda > ... > > Graphics.h > #ifndef _GRAPHICS_C > #define GRAPHICS_EXTERN extern > #else > #define GRAPHICS_EXTERN > #endif > > GRAPHICS_EXTERN int banana; > GRAPHICS_EXTERN int wibble; > > Thus, in Graphics.C, wibble and banana are defined without the 'extern' keyword, but if I include > graphics.h in any other file, they are defined 'extern'. banana and wibble are not defined in > Graphics.c, but graphics.h. I'm sure there must be a better way of doing this though. > > Cheers, > > James > . All this stuff is very useful. Thanks guys. Basically the way I see it, you add the #ifndef stuff in your header file to prevent the same things being defined twice (which can happen if you #include the same header files in multiple source files) Phil