Using macros as statements (Re: Typeof operator in C)
``Bob'' is the gun and YOU are the bullet...
david at sun.com
Wed Jan 17 09:52:22 AEST 1990
In article <19840 at watdragon.waterloo.edu> smking at lion.waterloo.edu (Scott
M. King) writes:
>To make a macro behave exactly as a statement, replace the { and } in
>the macro definition with START_MACRO and END_MACRO:
>#define START_MACRO do {
>#define END_MACRO } while ( 0 )
Unfortunately this is not lint-compatible ("constant in conditional
context"). I use a slight variation:
#ifdef lint
int _ZERO_;
#else
#define _ZERO_ 0
#endif
#define _STMT(s) do { s } while (_ZERO_)
#define FOO(bar) _STMT(if (bar) frob();)
--
David DiGiacomo, Sun Microsystems, Mt. View, CA sun!david david at eng.sun.com
More information about the Comp.lang.c
mailing list