我在某处读到过
#define X defined(Y)
无效,但似乎有效。
这是一个例子:
#define WIN_PLAT defined(_WIN32)
#if WIN_PLAT
# undef WIN_PLAT
# define WIN_PLAT 1
#else
# undef WIN_PLAT
# define WIN_PLAT 0
#endif
宏是文本替换,只要将
defined(Y)
替换回预处理器指令,它就会起作用。然而,如果您尝试在 C++ 代码中使用它,它将不起作用:
cout << X; // error: undefined symbol defined