問(wèn)題描述
在瀏覽 msdn 站點(diǎn)時(shí),他們使用的大多數(shù)條件檢查位置 (NULL == bCondition).
While exploring msdn sites ,most of the condition checking places they are using (NULL == bCondition).
使用這些符號(hào)的目的是什么?
what is the purpose of using these notations?
請(qǐng)?zhí)峁┮恍┦纠齺?lái)解釋這些.
Provide some sample to explain these please.
謝謝.
推薦答案
當(dāng)賦值運(yùn)算符 =
被意外使用而不是比較運(yùn)算符 ==
:
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 在前一種情況下會(huì)給出警告,很多語(yǔ)言都沒(méi)有這樣的警告.
C-compiler gives a warning in the former case, there are no such warnings in many languages.
這篇關(guān)于這些 (bCondition == NULL) 和 (NULL==bCondition) 之間有什么區(qū)別?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!