#define X Defined(Y) 是有效的 C/C++ 宏定义吗?

问题描述 投票:0回答:1

我在某处读到过

#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
c++ c macros c-preprocessor
1个回答
0
投票

宏是文本替换,只要将

defined(Y)
替换回预处理器指令,它就会起作用。然而,如果您尝试在 C++ 代码中使用它,它将不起作用:

cout << X; // error: undefined symbol defined
© www.soinside.com 2019 - 2024. All rights reserved.