3 ms·
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)
by trealira 3y ago
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."