简体   繁体   English

C ++中的#ifdef 1是什么?

[英]What does #ifdef 1 in C++

in C++, I know that programmers use #ifdef 0 to block out code from running, but in this same project I see a lot of #ifdef 1 . 在C ++中,我知道程序员使用#ifdef 0阻止代码运行,但在同一个项目中我看到了很多#ifdef 1 Does this mean that the code always runs? 这是否意味着代码总是运行? Unfortunately the code does not compile so I can't just run and test! 不幸的是代码没有编译所以我不能只运行和测试!

#ifdef 1 is ill-formed. #ifdef 1不正确。 The #ifdef directive requires a single identifier; #ifdef指令需要一个标识符; 1 is not an identifier. 1不是标识符。

#ifdef x is equivalent to #if defined(x) . #ifdef x相当于#if defined(x) The defined preprocessing operator yields true if the identifier names a defined macro (ie, a macro that has been defined with #define and not yet undefined via #undef ) and false otherwise. 如果标识符命名一个已定义的宏(即,已使用#define定义但尚未通过#undef定义的宏),则defined预处理运算符将返回true ,否则返回false

The #if directive enables or disables compilation of the lines between it and the corresponding #else , #elif , or #endif directive that follows it (the directives nest). #if指令启用或禁用它与它#elif的相应#else#elif#endif指令(指令嵌套)之间的行的编译。

Chances are, what you are really looking for is #if 1 (or #if 0 ), which is valid. 你可能正在寻找的是#if 1 (或#if 0 ),这是有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM