The solution for function-like
macros proposed by
tftv256 is so brilliant that nobody else seems to have thought of it before.
I used to define this sort of macros like
#define FOO() foo(), bar()
This also works fine, even with a piece of logic:
#define FOO(x) (x) ? foo1() : foo2(), bar()
But what if you need a for statement in your definition? And what do you do if you have use another persons definition and this is one of the sort:
#define FOO() { foo(); bar(); }
The most unpleasant example I ever found was
#define SURPRISE(x) if ((x)) foo()
You will really get surprising results if you use this example as in:
if (a) SURPRISE(b); else somethingelse();
You expect somethingelse() to be executed if a is 0, but is isn't!
To avoid problems with using functions which might be implemented as function-like macros, I always use blocks and never statements where both are allowed by the incredible C syntax. So:
if( bort ) {
FOO();
} else {
bam = bob;
}
and
if ( a ) {
SURPRISE(b);
} else {
somethingelse();
}
The braces may be considered ugly, but they make sure that the program does what I expect it to do.