小编Chr*_*ris的帖子

我可以测试预处理器指令的值吗?

我有一个未设置的预处理器指令,因此我无法更改它,它要么是 true 要么是 false。

通常我会这样做:

#ifdef DIRECTIVE
// code
#endif
Run Code Online (Sandbox Code Playgroud)

但这将始终运行,因为DIRECTIVE始终已定义。

有没有一种方法可以基本上相当于:

#if DIRECTIVE
#endif
Run Code Online (Sandbox Code Playgroud)

我想我可以做

bool DirectiveValue = DIRECTIVE;
if (DirectiveValue){

}
Run Code Online (Sandbox Code Playgroud)

但我真的希望第二个代码块能够以某种方式实现。

感谢您的任何见解!

c++ preprocessor c-preprocessor

0
推荐指数
1
解决办法
586
查看次数

标签 统计

c++ ×1

c-preprocessor ×1

preprocessor ×1