Article View: comp.std.c
Article #5333Re: Variable length arg lists for macros
From: Chris Torek
Date: Thu, 15 Sep 1988 13:50
Date: Thu, 15 Sep 1988 13:50
27 lines
1322 bytes
1322 bytes
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
Technical Details
Message-ID:
<13573@mimsy.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!haven!cvl!mimsy!chrisReferences:
<438@ucsvc.unimelb.edu.au> <1036@cbnews.ATT.COM> <228@itivax.UUCP> <362@island.uu.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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