Calling multiple functions in a macro.
Dave Hammond
daveh at marob.MASA.COM
Thu Nov 3 03:16:42 AEST 1988
In article <7462 at ihlpl.ATT.COM> knudsen at ihlpl.ATT.COM (Knudsen) writes:
>In article <353 at marob.MASA.COM>, daveh at marob.MASA.COM (Dave Hammond) writes:
>> #define FOO() do { foo1(); foo2(); foo3() foo4(); } while(0)
>Why use the do and while? C has blocks, you can say just plain
> {foo1(); ... foo4();}
>Of course all you're really doing is supplying the braces so the
>macro can be used "without braces" in the source.
>I dimly recall defining macros wrapped in {}; they worked fine.
Except that invoking FOO(); (note the semicolon) introduces a null
statement which could easily throw off the flow (or fail to compile)
if used within a conditional expression. You would have to to invoke
FOO() without a terminating semicolon which, to me, is unnatural.
Dave Hammond
UUCP: ...!uunet!masa.com!{marob,dsix2}!daveh
DOMAIN: daveh at marob.masa.com
----------------------------------------------------------------------------
More information about the Comp.lang.c
mailing list