Hacker News new | ask | show | jobs
by iano 4383 days ago
Not entirely related to the post, but what's the sane use case for doing:

  return (expr, expr)
like in the first example? I cannot think of a good reason to do this.
4 comments

It may not be a good reason to do this, but you can condense

    if (failure) {
        errno = EINVAL;
        return -1;
    }
into

    if (failure)
        return (errno = EINVAL, -1);
In any sane code, you'd have the open and close brackets anyways, so all this code does is trade a few '\n' characters for a few parentheses characters. I'd opt for the former still.
If the min macro would have worked, it would have allowed the two lines

    min(1, 2, out);
    return out;
to be condensed into one line.
I know this mainly as a useful macro implementation trick if where you want to be able to use it in an expression.
It simplifies the grammar, immensely.