What is the difference between these (bCondition == NULL) and (NULL==bCondition)?

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 gives a warning in the former case, there are no such warnings in many languages.

Leave a Comment