Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Using Macros Message-ID: <3526@goanna.cs.rmit.oz.au> Date: 8 Aug 90 06:18:11 GMT References: <14339@shlump.nac.dec.com> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 28 In article <14339@shlump.nac.dec.com>, farrell@onedge.enet.dec.com (Bernard Farrell) writes: > In article <362.26be9dcc@astro.pc.ab.com>, yoke@astro.pc.ab.com (Michael Yoke) writes... [asks about defining macros that expand to more than one statement] > }; > > The presence of an empty statement after > the closing brace should not cause any problems, I wasn't going to reply to this, but the Official Free Answer[*] is to use the expansion do { /* your statements go here */ } while (0) This will work in any context where a statement is allowed; it wants a semi-colon after it just like a simple function call would. For example: #define swap(Type,x,y) do { \ Type *ZZQ1 = &(x); \ Type *ZZQ2 = &(y); \ Type ZZQ3 = *ZZQ1; \ *ZZQ1 = *ZZQ2; *ZZQ2 = ZZQ3; \ } while (0) (Exercise for the reader: why did I write 3 declarations instead of 1?) [*] An Official Free Answer is something you find in an FSF manual, such as the manual for CCCP. -- Taphonomy begins at death.