Equivalent to the "multiRet" function there and, I think, easier to follow:
int multiRet() {
if (!a) return 0;
if (!b) return 1;
return c ? 2 : 0;
}
The singleRet function, as someone else already pointed out, actually has different behaviour (as well as being, in my view, just slightly
harder to read and reason about):
int singleRet() {
if (!a) return 0;
return (b&&c) ? 2 : 1;
}
Both of these seem to me much much clearer than the multiply-nested versions there, and much clearer than introducing a new variable for the sake of a single return point.
(The other way to get a single return point here is to turn the code into a nest of ?: operators. I claim that will be less readable and more error-prone for most C programmers.)
I can't recall any instance I've ever seen where code became simpler or easier to follow as a result of turning multiple return points into a single return point.