Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define macro inside macro?

Tags:

c

macros

I want to use macro parameter like this:

  #define D(cond,...) do{         \
    #if cond                      \
    #define YYY 1                 \
    #else                         \
    #define YYY 0                 \
  } while(0)

Is it possible?

UPD
Maybe when sources will be preprocessed twice: gcc -E source.c | gcc -xc - next will work:

#define D(cond,...) #define YYY cond&DEBUG
#if YYY
#define D(...) printf( __VA_ARGS__ )
#else
#define D(...)
#endif
like image 548
Eugen Konkov Avatar asked Dec 04 '22 20:12

Eugen Konkov


1 Answers

No, because C 2011 [N1570] 6.10.3.4 3 says, about macro replacement, “The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one,…”

like image 112
Eric Postpischil Avatar answered Dec 25 '22 15:12

Eric Postpischil