Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!xylogics!transfer!lectroid!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Using Macros Summary: do {body} while(0) Message-ID: <151@smds.UUCP> Date: 8 Aug 90 03:33:26 GMT References: <14339@shlump.nac.dec.com> Organization: SMDS Inc., Concord, MA Lines: 21 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.