...

View Full Version : How to extern #DEFINE?



dealmaker
08-15-2008, 01:25 AM
Hi,
I am a module that uses several #DEFINE values that are defined in other modules. I tried extern, but it doesn't seem to work with #DEFINE. I don't want to include other modules' header files in the source file of the module because I want to keep this module independent, and I try not to change these DEFINE into global variables in order to use extern. How do I do this?

Thank you.

oracleguy
08-15-2008, 03:33 AM
You need to put them in a header file and just share the header file between the two modules. #defines are preprocessor directives and as such are processed and removed from the code before the linker processes extern statements.

dealmaker
08-15-2008, 04:49 AM
But there are multiple modules that are using this module and I don't link them all into same executable. And each module has a different value for the #DEFINE. So I have to use #ifdef and #include which is what I don't want to do.


You need to put them in a header file and just share the header file between the two modules. #defines are preprocessor directives and as such are processed and removed from the code before the linker processes extern statements.

oracleguy
08-15-2008, 06:06 PM
If they have different values for the defines, why do you want to share them?

But it boils down to that you can't share #define values with extern. The only way to share them is through a header file or through the compiler options. Most compilers allow you to set preprocessor defines in the command line when you compile the file.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum