Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to extern #DEFINE?

    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.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    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.

    Quote Originally Posted by oracleguy View Post
    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.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •