The Joy of Modular Macros

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Fri Jan 19 08:59:53 AEST 1990


In article <1990Jan18.002842.441 at aqdata.uucp> sullivan at aqdata.uucp (Michael T. Sullivan) writes:
> From article <21068 at stealth.acf.nyu.edu>, by brnstnd at stealth.acf.nyu.edu:
> > #define block do {
> > #define endblock } while(0)
    [ and then I go on to use block and endblock in the swap macro ]
> Why are "block" and "endblock" even bothered with here.  Why not just
> put the "do {" and "} while (0)" in the definition of swap?  Could
> somebody please enlighten me.

It's a secret plot to render your machine useless by wasting
microseconds of cpp time. :-)

Seriously, I use block and endblock because that's how I think about the
structure. Modularization makes programs easier to read and understand;
here it insulates swap from changes in the expression of block/endblock.
Is that sufficiently enlightening?

---Dan



More information about the Comp.lang.c mailing list