Using Macros
Richard Harter
rh at smds.UUCP
Wed Aug 8 13:33:26 AEST 1990
Sigh. I will probably be one of many posting this, but this seems
to have already generated some confusion. Shouldn't this be in
the "most frequently asked questions" posting?
If you have a block of statements defined in a macro which you
wish to use as though it were a function, there are several ways
to handle it. Perhaps the clearest is:
#define A_MACRO(args) do {...body...} while(0)
This makes A_MACRO a statement. This protection is needed when
you have A_MACRO in an if statement, e.g.
if (foo==bar) A_MACRO(moby);
else B_MACRO(gumby);
--
Richard Harter, Software Maintenance and Development Systems, Inc.
Net address: jjmhome!smds!rh Phone: 508-369-7398
US Mail: SMDS Inc., PO Box 555, Concord MA 01742
This sentence no verb. This sentence short. This signature done.
More information about the Comp.lang.c
mailing list