Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: macros and semicolons Message-ID: <14584.Jun2723.51.2191@kramden.acf.nyu.edu> Date: 27 Jun 91 23:51:21 GMT References: <1991Jun24.213932.595@otago.ac.nz> <160662@pyramid.pyramid.com> <6531@goanna.cs.rmit.oz.au> Organization: IR Lines: 17 In article <6531@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > #define swap(Type, This, That) \ > do { \ > Type *ThisQZ = &(This), *ThatQZ = &(That), t; \ > t = *ThisQZ, *ThisQZ = *ThatQZ, *ThatQZ = t; \ > } while (0) You should call this SWAP. Without the uppercase, someone might be fooled into thinking that it works like a function. Namespace issues aside, there are three problems with this as a function: (1) You're using This and That by reference. (2) You're passing a Type argument. (3) This is a statement rather than an expression. SWAP(x,y,int) would be fine, though I don't think you lose anything by making the user indirect x and y: SWAP(&x,&y,int). ---Dan