News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Multiple Source Files and #defines

Started by geronet, July 31, 2006, 05:49:31 PM

Previous topic - Next topic

geronet

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

rcoll

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


Game_Ender

Just the trick I was looking for, thank you.