简体   繁体   English

为什么 (1 && !A) 在 C++ 预处理器中

[英]Why do (1 && !A) in c++ pre-processor

In some c++ file I found在我发现的一些 C++ 文件中

#ifndef
#define A (1 && !B)
#endif

(with B having a default vale that can be overridden at compile time). B有一个可以在编译时覆盖的默认值)。 What is the difference with和有什么区别

#ifndef
#define A (!B)
#endif

Is it in order to prevent warnings on some specific compiler?是为了防止在某些特定编译器上出现警告吗?
(Exact code is in the Unreal Engine, I only simplified the macro names.) (确切的代码在虚幻引擎中,我只是简化了宏名称。)

Nobody is perfect, not even the authors of the Unreal Engine.没有人是完美的,甚至虚幻引擎的作者也不例外。

Setting aside any possibility of operator overloading, the type and values of the two expressions are identical.撇开运算符重载的任何可能性,两个表达式的类型和值是相同的。 I suspect (and it's only a hunch), that the author is forgetting that the type of (!B) is a bool in C++.怀疑(这只是一种预感),作者忘记了(!B)的类型是 C++ 中的bool

(1 && !B) is more explicitly perhaps a bool type as it contains the && operator. (1 && !B)可能更明确地是bool类型,因为它包含&&运算符。

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

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