Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!natinst!rpp386!tqc!eric From: eric@tqc.FIDONET.ORG (Eric Rouse) Newsgroups: comp.lang.c Subject: Is this swap() macro correct? Message-ID: <113.25B72444@tqc.FIDONET.ORG> Date: 18 Jan 90 14:33:01 GMT Organization: The Q Continuum -- Austin, Tx Lines: 19 > Message-ID: <21068@stealth.acf.nyu.edu> > > Say swap() is defined as > > #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; As long as your working with base types, or types you can cast to a base types like integers, longs etc, you might look into this one: #define Swap(X1,X2) { X1 ^= X2; X2 ^= X1; X1 ^= X2; } It's quite nice for integers, unsigned, longs, pointers etc. Plus it doesn't use any temp storage. Eric Rouse -- via The Q Continuum (FidoNet Node 1:382/31) UUCP: ...!rpp386!tqc!eric ARPA: eric@tqc.FIDONET.ORG