Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!hao!oddjob!gargoyle!ihnp4!ihlpg!tainter From: tainter@ihlpg.ATT.COM (Tainter) Newsgroups: comp.lang.c Subject: Re: swap via xor Message-ID: <4721@ihlpg.ATT.COM> Date: 29 Jan 88 16:48:00 GMT References: <8801200422.AA19420@decwrl.dec.com> <3061@killer.UUCP> <10366@mimsy.UUCP> Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 23 In article <10366@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > Let me see if I can lay this to rest. If you hadn't said this I probably would have let it go. :-) > a ^= b; b ^= a; a ^= b; > will swap `a' and `b' if the `^' operator can be applied at all. > There is no way within C (short of `#define a b' or equivalent) to > make this fail. Actually if a or be are expressions with side effects you have a problem. i.e. given char *a, *b; swap(a++,b++); defined as above goes splooot. > In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) --j.a.tainter