Xref: utzoo comp.std.c:379 comp.lang.c:12618 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!haven!cvl!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.std.c,comp.lang.c Subject: Re: Variable length arg lists for macros Message-ID: <13573@mimsy.UUCP> Date: 15 Sep 88 13:50:48 GMT References: <438@ucsvc.unimelb.edu.au> <1036@cbnews.ATT.COM> <228@itivax.UUCP> <362@island.uu.net> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 27 In article <362@island.uu.net> walker@island.uu.net (Richard Walker) suggests that >... macros which expand into code with flow control >should be formed such that the semicolon cleanly terminates >the flow, e.g.: > >#define COMPLEX_MACRO(foo) (if(SOME_TEST(foo)) {statements;}else) This works (after correcting the syntax), but I recommend instead #define MAC() if (!(normal_test)) /*void*/; else mac_statement or, if you need {}s, #define MAC() do { mac_statements } while (0) These have the advantage over the one above that MAC() /* missing semicolon */ next_stmt; produces a syntax error, rather than code that reads if (some_test) { statements; } else next_stmt; -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris