Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

Conditional Preprocessor macro expansion in C

$
0
0

I have a macro, SOME_MACRO. It takes an argument.

Definition of SOME_MACRO:

#define SOME_MACRO(arg) __SOME_MACRO(arg)

Further I want __SOME_MACRO(arg) to expand to "ABC" if arg is 0. And if arg is not zero, __SOME_MACRO(arg) should expand to "DEF"

Suppose I call with argument 0, that is: SOME_MACRO(0)I need to test at preprocessing time, whether the argument is zero or not.

#if <argument is zero>     // line 1#define __SOME_MACRO(arg) "ABC"#elif#define __SOME_MACRO(arg) "DEF"#endif

My question is: What should be at line 1?

Taking an example:

SOME_MACRO(2) should expand to "DEF"

SOME_MACRO(0) should expand to "ABC"

Please only give solution(s) to above problem. Do not give alternative approaches or better ways to solve the problem.


Viewing all articles
Browse latest Browse all 22016

Trending Articles