Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C++ 中,我知道程序员#ifdef 0用来阻止代码运行,但在同一个项目中,我看到了很多#ifdef 1. 这是否意味着代码总是运行?不幸的是,代码无法编译,所以我不能只运行和测试!
#ifdef 0
#ifdef 1
#ifdef 1格式不正确。该#ifdef指令需要一个标识符;1不是标识符。
#ifdef
1
#ifdef x相当于#if defined(x)。如果标识符命名了已定义的宏(即,已使用via 定义但尚未未定义的宏),则defined预处理运算符产生,否则。true#define#undeffalse
#ifdef x
#if defined(x)
defined
true
#define
#undef
false
该#if指令启用或禁用它与它后面的相应 、 或 指令之间的行的编译#else(#elif指令#endif嵌套)。
#if
#else
#elif
#endif
很有可能,您真正要寻找的是#if 1(或#if 0),这是有效的。
#if 1
#if 0