这些 (bCondition == NULL) 和 (NULL==bCondition) 之间有什么区别?

What is the difference between these (bCondition == NULL) and (NULL==bCondition)?(这些 (bCondition == NULL) 和 (NULL==bCondition) 之间有什么区别?)
本文介绍了这些 (bCondition == NULL) 和 (NULL==bCondition) 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在浏览 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) 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

What do compilers do with compile-time branching?(编译器如何处理编译时分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗?)
Checking for NULL pointer in C/C++(在 C/C++ 中检查空指针)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比较运算符的数学式链接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之间的区别与“if())
C++, variable declaration in #39;if#39; expression(C++,if 表达式中的变量声明)