Path: utzoo!attcan!uunet!cs.utexas.edu!usc!bbn.com!diamond.bbn.com!mlandau From: mlandau@bbn.com (Matthew Landau) Newsgroups: comp.lang.c Subject: Re: Using Macros Message-ID: <14404@diamond.BBN.COM> Date: 7 Aug 90 20:00:19 GMT References: <14339@shlump.nac.dec.com> Sender: news@bbn.com Lines: 20 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) Since there's no trailing semicolon after the while(0), this construct can be used anywhere a simple C statement can be used. (Indeed, syntactically it is one statement.) Moreover, any compiler worth its salt should be able to optimize away the do ... while part, since the code above is guaranteed to execute the stuff inside the braces exactly once. Of course lint and Saber will complain bitterly, but you can shut Saber up with judicious use of the SUPPRESS directive in the macro definition. Still haven't figured out how to get lint to quiet down, but then again I don't use lint much now that I have Saber. -- Matt Landau Oblivion gallops closer, mlandau@bbn.com favoring the spur, sparing the rein.