News for hackers. Stuff that matters.
Re:C23: A Slightly Better C by trealira on Sunday January 21, 2024 @04:13PM (#39083129)
If you simply put braces around it, you'd generate syntactically invalid code when you don't use braces for if-else statements.

Consider this:

  if (e)
      SWAP(a, b);
  else
     something_else();
Currently, that expands to this, which is still valid code:

  if (e)
      do {
          // ...macro...
      } while(0);
  else
      something_else();
If it were just wrapped in braces, the code would be parsed like this:

  // One-armed if-statement
  if (e) {
      // ...macro...
  }

  // Empty statement
  ;

  // Another statement
  else something_else();
It's incorrect syntax to start a statement with else, so the compiler will say something like "Unexpected 'else' at line N."
Re:C23: A Slightly Better C by kstrauser on Sunday January 21, 2024 @04:57PM (#39083501)
I would not have come up with that on my own. Thanks for the explanation!
Re:C23: A Slightly Better C by trealira on Sunday January 21, 2024 @05:15PM (#39083639)
No problem! I didn't come up with it on my own, either. I simply read it somewhere, and now I'm repeating it.