C : is there "lazy evaluation" when using && operator, as in C++?

Pac0 picture Pac0 · Oct 18, 2010 · Viewed 12.7k times · Source

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?

Answer

codaddict picture codaddict · Oct 18, 2010

Yes && is short circuited and you are using it correctly.
If next is NULL string compare will never happen.