upoque
upoque

Reputation: 53

Preprocessor macro that inserts another preprocessor macro

Is there a way to insert preprocessor macro using another preprocessor macro?

Can I do something like, for instance

    #define INSERT_MACRO(x) {#ifdef MYFLAG x; #endif}

so that when I write

    INSERT_MACRO(foo(););

it is converted to

    #ifdef MYFLAG
    foo();
    #endif

? Thanks!

Upvotes: 0

Views: 55

Answers (1)

Eric
Eric

Reputation: 471

You cannot use another preprocessor directive in define. Instead you may consider,

#ifdef MYFLAG
#define INSERT_MACRO(x) x;
#else
#define INSERT_MACRO(x) 
#endif

Upvotes: 1

Related Questions