Hacker News new | ask | show | jobs
by kazinator 3223 days ago
The comma operator has more uses than that. One of them is to introduce some needed side effect in a sequence of definitions, without introducing a statement (out of esthetics, or C90 compatibility concerns):

  {
    int x = (side_effect(), initializing_expr());
    int y = x + 42;
From C99 onward, this could be:

  {
    side_effect();
    int x = initializing_expr();
    int y = x + 2;
We use the comma operator in for loops because it has places in its syntax which take one expression. This limitation can arise in other contexts, like some macro MAC(E) where E must be a single expression. If want to to have two sequenced effects in there, we can use MAC((eff1, eff2)).