I would like to know if this looks correct :
while((next !=NULL) && (strcmp(next->name, some_string) < 0) {
//some process
}
I mean, if next is NULL
, then the second part of the expression won't be ever tested by the compiler? I have heard that in C++ it's the case (but I'm not even sure of it).
Can someone confirm me that I won't get strange errors on some compilers with that?
(next != NULL)
may use an overloaded!=
operator on whatever typenext
is. That operator may return another type on which&&
is overloaded. And for overloaded&&
there is no built-in short-circuiting, so the expression on the RHS will be evaluated regardless of the LHS. – Gush