在浏览 msdn 站点时,他们使用的大多数条件检查位置 (NULL == bCondition).
While exploring msdn sites ,most of the condition checking places they are using (NULL == bCondition).
使用这些符号的目的是什么?
what is the purpose of using these notations?
请提供一些示例来解释这些.
Provide some sample to explain these please.
谢谢.
当赋值运算符 = 被意外使用而不是比较运算符 ==:
The use of NULL == condition provides more useful behaviour in the case of a typo, when an assignment operator = is accidentally used rather then the comparison operator ==:
if (bCondition = NULL) // typo here
{
// code never executes
}
if (NULL = bCondition) // error -> compiler complains
{
// ...
}
C-compiler 在前一种情况下会给出警告,很多语言都没有这样的警告.
C-compiler gives a warning in the former case, there are no such warnings in many languages.
这篇关于这些 (bCondition == NULL) 和 (NULL==bCondition) 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
编译器如何处理编译时分支?What do compilers do with compile-time branching?(编译器如何处理编译时分支?)
我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗?)
在 C/C++ 中检查空指针Checking for NULL pointer in C/C++(在 C/C++ 中检查空指针)
比较运算符的数学式链接-如“if((5<j<=1))&quMath-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比较运算符的数学式链接-如“if((5<j<=1)))
“if constexpr()"之间的区别与“if()"Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之间的区别与“if())
C++,'if' 表达式中的变量声明C++, variable declaration in #39;if#39; expression(C++,if 表达式中的变量声明)