Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.c Subject: Re: Using Macros Message-ID: Date: 8 Aug 90 00:34:11 GMT References: <14339@shlump.nac.dec.com> <14404@diamond.BBN.COM> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 24 In-Reply-To: mlandau@bbn.com's message of 7 Aug 90 20:00:19 GMT In article <14404@diamond.BBN.COM> mlandau@bbn.com (Matthew Landau) writes: Seems like this should be on the FAQ list, since it comes up every couple of months. My preferred solution to the problem (which I picked up in comp.lang.c about 10 years ago :-) is: #define FOO(bar, baz) do { func1(bar); func2(baz); } while (0) Hmmm, when I first saw the problem posted, I thought I knew the easy and consistent answer, but all these other responses differ from mine. Can anyone explain to me why #define FOO(bar,baz) (func1(bar), func2(baz)) wouldn't work in all the situations one could reasonably expect? The macro still expands to a single expression (as did the old version mentioned in the original posting), right? So a trailing semicolon causes it to be interpreted as a statement, right? The comma within the expansion serves the same purpose of defining a sequence point as would the semicolon in other solutions, right? I have the horrible feeling I'm missing something, but I do think I've done this before and it worked okay. James Craig Burley, Software Craftsperson burley@world.std.com