Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Now, let us suppose that expression a has side-effects...

"But that's just stupid!"

Yes. Now, given that a has side-effects...


Assuming 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.


Suppose I want to `printf("Returning. A: %i", a)`. Same answer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: