Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: geronet on July 31, 2006, 05:49:31 pm

Title: Multiple Source Files and #defines
Post by: geronet on July 31, 2006, 05:49:31 pm
Hello, easy description of the problem:
If i try to use this (watch the part with "You can achieve this with the help of..."):

http://www.eng.cam.ac.uk/help/tpl/languages/C/teaching_C/node29.html

it doesn't work. I wonder why?
Using the gcc with XP.

Thanks in advance, Stefan
Title: Re: Multiple Source Files and #defines
Post by: rcoll on July 31, 2006, 06:14:16 pm
This works fine for me.  It has worked fine for more years than I care to remember.

In my area, it is SOP to do something like:

(in the header file)

#ifdef _MYFILE_C_
#define EXTERN
#else
#define EXTERN   extern
#endif

EXTERN   int   my_var;

(in the main code module)

#define  _MYFILE_C_
#include "myfile.h>


This ensures the globals are defined only in "myfile.c",
but declared extern everywhere else.

Cheers,
Ron

Title: Re: Multiple Source Files and #defines
Post by: Game_Ender on July 31, 2006, 06:48:58 pm
Just the trick I was looking for, thank you.