Path: utzoo!utgpu!attcan!uunet!seismo!sundc!pitstop!sun!amdcad!ames!nrl-cmf!cmcl2!phri!marob!daveh From: daveh@marob.MASA.COM (Dave Hammond) Newsgroups: comp.lang.c Subject: Re: Calling multiple functions in a macro. Message-ID: <354@marob.MASA.COM> Date: 2 Nov 88 17:16:42 GMT References: <353@marob.MASA.COM> <7462@ihlpl.ATT.COM> Reply-To: daveh@marob.masa.com (Dave Hammond) Organization: ESCC New York City Lines: 18 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 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@marob.masa.com ----------------------------------------------------------------------------