Using Macros

Tim McDaniel mcdaniel at adi.com
Wed Aug 8 08:59:51 AEST 1990


yoke at astro.pc.ab.com (Michael Yoke) asks about multiple-statement
macros.

1. The comma operator, which only works for expressions:
	#define A_MACRO		(expr1, ..., exprn)

2. 
	#define A_MACRO		do { stmt1; ...; stmtn; } while (0)
   Any decent compiler should optimize the useless test out.
   Even if it doesn't, it shouldn't hurt speed much.
   Lint may require help to shut up about a "constant in a conditional
   context", or such.
--
"I'm not a nerd -- I'm 'socially challenged'."

Tim McDaniel
Internet: mcdaniel at adi.com             UUCP: {uunet,sharkey}!amara!mcdaniel



More information about the Comp.lang.c mailing list