Path: utzoo!yunexus!geac!syntron!jtsv16!uunet!lll-winken!arisia!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Calling multiple functions in a macro. Message-ID: <617@quintus.UUCP> Date: 2 Nov 88 08:35:51 GMT Article-I.D.: quintus.617 References: <353@marob.MASA.COM> <7462@ihlpl.ATT.COM> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 17 In article <7462@ihlpl.ATT.COM> knudsen@ihlpl.ATT.COM (Knudsen) writes: >In article <353@marob.MASA.COM>, daveh@marob.MASA.COM (Dave Hammond) writes: >> #define FOO() do { foo1(); foo2(); foo3() foo4(); } while(0) >Why use the do and while? C has [compound statements], you can say just plain > {foo1(); ... foo4();} Answer: so you can write if (test) foo(); else baz(); With Hammond's definition, the expansion is if (test) do { ... } while (0); else baz(); which is valid. With Knudsen's definition, the expansion is if (test) { ... } ; else baz(); which is **not** syntactically valid. If you want a macro to be usable as an expression, use (...) If you want a macro to be usable as a statement, use do { ... } while (0) If C had remained syntactically closer to BCPL and copied less of PL/I's syntactic arsenic, we'd have been spared a fair bit of irritation.