Thread: conditional text substitution by the preprocessor

  1. #1
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337

    conditional text substitution by the preprocessor

    I'm wanting to conditionally assign a modifier during a compile. I want to assign a modifier of "static" or "extern", depending on whether a given symbol is defined.

    That is what I'm trying to code. (I haven't use C macros much).


    Code:
    #ifdef _MYVAR_ 
       #define MODIFIER static 
    #else 
       #define MODIFIER extern 
    #endif 
    
    .
    .
    .
    MODIFIER int foo(char *) ;

    Can this be done? The above fails on the last line. I'm wanting either static or extern to be substituted.
    Mainframe assembler programmer by trade. C coder when I can.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    OMG. Never mind. I had a typo in my program. This works great when my spelling mistake was fixed. I had this:

    Code:
    #ifdef _MYVAR_ 
       #define MODIFIER static 
    #else 
       #define MODIFIER extern 
    #endif 
     
    .
    .
    .
    MODIFER int foo(char *) ;    // <-- note typo)
    Mainframe assembler programmer by trade. C coder when I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. !feof substitution
    By BIGDENIRO in forum C Programming
    Replies: 11
    Last Post: 11-30-2013, 08:03 PM
  2. Substitution from C to C++
    By nepper271 in forum C++ Programming
    Replies: 10
    Last Post: 12-10-2010, 11:33 AM
  3. Conditional compilation and the preprocessor
    By tempster09 in forum C Programming
    Replies: 2
    Last Post: 04-30-2010, 04:27 PM
  4. Substitution problem...
    By Junior89 in forum C++ Programming
    Replies: 21
    Last Post: 06-27-2007, 04:13 PM
  5. EQU substitution??
    By theeld in forum C Programming
    Replies: 1
    Last Post: 10-28-2006, 07:52 PM

Tags for this Thread