Author Topic: Multiple Source Files and #defines  (Read 3323 times)

Offline geronet

  • Multiple posting newcomer
  • *
  • Posts: 14
Multiple Source Files and #defines
« 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

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Multiple Source Files and #defines
« Reply #1 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


Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Multiple Source Files and #defines
« Reply #2 on: July 31, 2006, 06:48:58 pm »
Just the trick I was looking for, thank you.