C++ 中的 #ifdef 1 是什么意思?
在 C++ 中,我知道程序员使用 #ifdef 0
来阻止代码运行,但在同一个项目中我看到很多 #ifdef 1
。这是否意味着代码始终运行?不幸的是,代码无法编译,所以我不能运行和测试!
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
. Does this mean that the code always runs? Unfortunately the code does not compile so I can't just run and test!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#ifdef 1
格式不正确。#ifdef
指令需要一个标识符;1
不是标识符。#ifdef x
相当于#if Defined(x)
。如果标识符命名了已定义的宏(即已使用#define
定义且尚未未定义的宏,则define
预处理运算符将生成true
通过#undef
),否则为false
。#if
指令启用或禁用其与相应的#else
、#elif
或#endif< 之间的行的编译。 /code> 后面的指令(指令嵌套)。
很可能,您真正要寻找的是
#if 1
(或#if 0
),这是有效的。#ifdef 1
is ill-formed. The#ifdef
directive requires a single identifier;1
is not an identifier.#ifdef x
is equivalent to#if defined(x)
. Thedefined
preprocessing operator yieldstrue
if the identifier names a defined macro (i.e., a macro that has been defined with#define
and not yet undefined via#undef
) andfalse
otherwise.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).Chances are, what you are really looking for is
#if 1
(or#if 0
), which is valid.