NULL!= C ++中的值的含义是什么? [英] What is the meaning of NULL != value in C++?
问题描述
我经历了一段C ++代码,遇到了像
I was going through a piece of C++ code and came across a code like
if (NULL != threadInfo)
{
...
...
}
我只是想知道使用表达式之间是否有任何区别
I was just wondering is there any difference between using the expression
if (threadInfo != NULL)
{
...
...
}
上面说的是什么。
读取第一个读取如果NULL不等于ThreadInfo,第二个读取如果threadInfo不等于NULL。对我来说第二个更有意义。
what is said above. While reading the first one reads " If NULL not equals to ThreadInfo" and the second one reads "If threadInfo not equals to NULL". To me the second one makes more sense.
推荐答案
不,没有区别。在 ==
的情况下可能会有一些区别。事情是,如果你不小心写了 =
而不是 ==
,编译器会在第一种情况下给出错误。
No, there is no difference. In case of ==
there might be some difference. The thing is that if you accidentally write =
instead of ==
the compiler will give an error in the first case.
if (threadInfo = NULL) //always false. The compiler will give you a warning at best
if (NULL = threadInfo) //Compiler error
b $ b
我个人讨厌这种做法,认为编写可以用正常人类语言阅读的代码更好,而不是Yoda语言。
I personally hate that practice and think it's better to write code that can be read in a normal human language, not Yoda language.
这篇关于NULL!= C ++中的值的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!