Is this swap() macro correct?

Michael T. Sullivan sullivan at aqdata.uucp
Thu Jan 18 11:28:42 AEST 1990


>From article <21068 at stealth.acf.nyu.edu>, by brnstnd at stealth.acf.nyu.edu:
> Say swap() is defined as
> 
> #define block do {
> #define endblock } while(0)
> #define swap(x,y,typ) block typ *_MV_x = x; typ *_MV_y = y; typ tmp;\
>                     tmp = *_MV_x; *_MV_x = *_MV_y; *_MV_y = tmp; endblock

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.
-- 
Michael Sullivan          uunet!jarthur!aqdata!sullivan
aQdata, Inc.              sullivan at aqdata.uucp
San Dimas, CA



More information about the Comp.lang.c mailing list