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

前端 未结 4 1548
后悔当初
后悔当初 2020-12-03 21:20

I would like to know if this looks correct :

while((next !=NULL) && (strcmp(next->name, some_string) < 0) {
    //some process
}
4条回答
  •  醉梦人生
    2020-12-03 22:01

    This will work with lazy evaluation (the second statement not evaluated if the first one is evaluated to "false") unless your compiler is so non-standard compliant it can't even be named a C compiler. Millions lines of code in the field rely on this behavior, so you can think that this behavior is just guaranted.

提交回复
热议问题