C中的宏条件语句

时间:2016-12-03 12:34:24

标签: c macros conditional c-preprocessor

是否可以在C中的宏函数内实现宏条件。像这样:

#define fun(x)
#if x==0
    fun1;
#else
    fun2;
#endif

#define fun1 // do something here
#define fun2 // do something else here

换句话说,预处理器根据参数值决定使用哪个宏。

fun(0) // fun1 is "preprocessed"
fun(1) // fun2 is "preprocessed"

我知道这个例子不起作用,但我想知道是否有可能让它以某种方式工作?

微米。

0 个答案:

没有答案
相关问题