First, it should not have the trailing ;
. It should be:
#define CALL_FUNCS(x) do { func1(x); func2(x); func3(x); } while (0)
Anyway, the reason is as follows. Consider
if(b)
CALL_FUNCS(x);
else
something_else(x);
This would expand to:
if(b)
{ func1(x); func2(x); func3(x); };
else
something_else(x);
Now we still have a trailling ;
and will get this error message:
error: ‘else’ without a previous ‘if’
Note, if you keep the ;
in the macro, then you will have two trailing ;
s!
Macro expansion should 'look' like something that expects a semicolon on the end. You're not going to type CALL_FUNCS(x)
, you're going to call CALL_FUNCS(x);
. You can rely on do.. while(0)
to slurp up the semicolon, but { }
will not do so.