I was wondering if there is a better way to handle the situation in C where you want to exit the function as soon as you encounter an error in a series of expressions. (in this case, it is a function that returns a NULL error on error)
eg. in some C code, where they tried to handle errors in short circuits by combining a number of operators with AND (& &).
return doSomething() &&
doSomething2() &&
doSomething3() && ... ;
This annoys me, as we click so much on one line in one of the statements. But I guess the alternative
if (!(value = doSomething()))
return NULL;
if (!(value = doSomething2()))
return NULL;
etc
return value;
But what about evaluating errors in the short circuits that I saw in the perl and bash scripts.
int die(int retvalue) {
exit(retvalue);
}
.....
(value = doSomething()) || die(1);
(value = doSomething2()) || die(2);
(value = doSomething3()) || die(3);
return value;
, RHS , . - ?
edit: , . , , .