It makes use of the macro act like a real statement or function call.
A statement is either { expression-list }
or expression;
so that poses a problem when defining macros that need more than one expression, because if you use { }
then a syntax error will occur if the caller of the macro quite reasonably adds a ;
before an else.
if(whatever)
f(x);
else
f(y);
If f()
is a single statement macro, fine, but what if it's a macro and something complicated? You end up with if(...) { s1; s2; }; else ...
and that doesn't work.
So the writer of the macro has to then either make it into a real function, wrap the construct in a single statement, or use a gnu extension.
The do .. while(0)
pattern is the "wrap the construct" approach.