Your main problem is that you did not initialize myInterface .
Assuming myInterfacee is just a typo, everything will be fine, and none of them will call doSometing :
IMyInterface* myInterface = 0; if ( myInterface ){ // ! removed myInterface->doSometing(); } if ( myInterface != 0 ) { // as before myInterface->doSometing(); } if ( myInterface != NULL ){ // as before myInterface->doSometing(); } if ( myInterface != ( IMyInterface* )0 ) { // IMyInterface, not myInterface myInterface->doSometing(); }
Personally, I prefer the first two over the third and do not like the fourth, but this is a matter of style, not correctness.
If myInterface is installed or not installed is still included in each statement
I kind of don't believe it, but if it really is (you initialize myInterface and you still see that both the if (!myInterface) and if (myInterface != 0) ), that is, something very wrong in elsewhere in your program. Those tests have opposite meanings, so the only way they will both look is when something undefined happens.
source share