4 ms·
Not to repeat myself, but: if (a) printf("returning b"); return a ? b : c; ...makes it easy to modify the side effects of the return without mu
by Cushman 14y ago
Not to repeat myself, but:
if (a)
printf("returning b");
return a ? b : c;
...makes it easy to modify the side effects of the return without muddying the semantics.
- to3m 14y agoNow, let us suppose that expression a has side-effects... "But that's just stupid!" Yes. Now, given that a has side-effects...
- Cushman 14y agoSuppose I want to `printf("Returning. A: %i", a)`. Same answer.
- georgeorwell 14y agoAssuming a has type int: int a_val = a; if (a_val) printf ("returning b"); return a_val ? b : c; Anyway, it's not useful for complicated code that needs to do lots of stuff. It's useful for simple code that ends up being more verbose with if-else. It's also useful for enforcing behaviour.