Using Macros

Alex Martelli staff at cadlab.sublink.ORG
Mon Aug 13 07:38:54 AEST 1990


brad at SSD.CSD.HARRIS.COM (Brad Appleton) writes:
...[some details omitted]...
>use of the logical operators || and &&. Using this, the following:
>	#define CHECK(cond)  { if (cond)  exit(-1);  }
>could be replaced by
>	#define CHECK(cond)  ((cond) || exit(-1))
>And wouldnt wreak havoc inside nested if statements.

Another technique I like for this very situation:

#define CHECK(cond) if(cond) exit(-1); else

...no havoc-wrecking here, either, and also work fine for cases where
the conditional action is, say, "return FAILURE_INDICATOR;" - AND no
lint complaints about constants in conditional contexts.  Only good for
CONDITIONAL macros, alas...

-- 
Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 45, Bologna, Italia
Email: (work:) staff at cadlab.sublink.org, (home:) alex at am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; 
Fax: ++39 (51) 366964 (work only; any time of day or night).



More information about the Comp.lang.c mailing list