C preprocessor: using #if inside #define?

Posted by Wxy on Stack Overflow See other posts from Stack Overflow or by Wxy
Published on 2010-05-14T05:03:31Z Indexed on 2010/05/14 5:14 UTC
Read the original article Hit count: 197

Filed under:
|

I want to write a macro that spits out code based on the boolean value of its parameter. So say DEF_CONST(true) should be expanded into "const", and DEF_CONST(false) should be expanded into nothing.

Clearly the following doesn't work because we can't use another preprocessor inside #defines:

#define DEF_CONST(b_const) \
#if (b_const) \
  const \
#endif

Any idea about how to do it?

© Stack Overflow or respective owner

Related posts about c

    Related posts about preprocessor