Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!amgraf!cpsolv!rhg From: rhg@cpsolv.CPS.COM (Richard H. Gumpertz) Newsgroups: comp.lang.c Subject: Re: Is this swap() macro correct? Message-ID: <486@cpsolv.CPS.COM> Date: 18 Jan 90 23:18:13 GMT References: <21068@stealth.acf.nyu.edu> Reply-To: rhg@cpsolv.uucp (Richard H. Gumpertz) Distribution: usa Organization: Computer Problem Solving, Leawood, Kansas Lines: 19 In article <21068@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: >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 > >Now constructions like swap(f++,g++,real) work and are faster than a Stylistic nit: I would make it &(x) and &(y) in the first line of swap and make typ the first parameter and then make the call you show be swap(real, *f++, *g++) Maybe I am strange, but I find that easier to read. -- ========================================================================== | Richard H. Gumpertz rhg@CPS.COM (913) 642-1777 or (816) 891-3561 | | Computer Problem Solving, 8905 Mohawk Lane, Leawood, Kansas 66206-1749 | ==========================================================================