Using Macros

Stephen Clamage steve at taumet.com
Fri Aug 10 01:32:56 AEST 1990


ckp at grebyn.com (Checkpoint Technologies) writes:

[ shows how to make up a macro with expressions, rather than statements ]

>Now this technique won't work if you really need multiple "statements",
>which could include things like return, break, if, while, etc., but it
>works just dandy for multiple expressions.

Actually, you can handle "if" statements by transforming them into
conditional expressions (c ? expr1 : expr2).  As long as neither the
"then" nor "else" clause contains "for", "while", "switch", "break",
or "goto", you can always do this, though it is occasionally awkward.
(I don't claim that you will always want to, just that you can.)
If there is no "else", just use zero for the second expression.
You will usually need to cast each expression to void to satisfy the
constraint of the conditional expression that each half must evaluate
to the same type.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list