by HarHarVeryFunny · 3y ago · 0 comments
Compare:
#define FOO() { ... }
#define BAR() do { ... } while (0)
In the former case: if (x)
FOO();
else
...;
// becomes
if (x) {
...
}
;
else
...;
In the latter case: if (x)
BAR();
else
...;
// becomes
if (x)
do {
...
} while (0);
else
...;I just discovered that gcc also supports non-standard "statement expressions" of the form ({...}) which would serve the same purpose at the cost of portability.