Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!mailrus!uflorida!novavax!proxftl!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Calling multiple functions in a macro. Message-ID: <139@twwells.uucp> Date: 2 Nov 88 01:12:52 GMT References: <353@marob.MASA.COM> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 34 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <353@marob.MASA.COM> daveh@marob.masa.com (Dave Hammond) writes: : In attempting to construct a macro which calls several functions, : but can be used as a single statement (i.e. without braces in an if/else : construct), I can see 2 possible alternatives: : : 1. : #define FOO() do { foo1(); foo2(); foo3() foo4(); } while(0) : : 2. : #define FOO() foo1(), foo2(), foo3(), foo4() : : The first adds quite a bit of code to the program and makes lint : complain about constants in conditional text. The first is unlikely to add that much to the code. Go look at the assembly output. : The second compiles, executes and lints correctly (on Xenix), but : is it portable to string function calls in this manner? Yes it is portable. But save yourself some headaches and write it: #define FOO() (foo1(), foo2(), foo3(), foo4()) The extra parentheses can prevent problems with, e.g.: a + FOO() which would otherwise add a to the result of foo1 and toss the result, when what you want it to do is add it to foo4 and return the result. --- Bill {uunet|novavax}!proxftl!twwells!bill