Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!umd5!cvl!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: swap via xor Message-ID: <10366@mimsy.UUCP> Date: 28 Jan 88 02:31:13 GMT References: <8801200422.AA19420@decwrl.dec.com> <3061@killer.UUCP> <1182@ark.cs.vu.nl> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 16 Let me see if I can lay this to rest. 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. On the other hand, *p ^= *q; *q ^= *p; *p ^= *q; can fail if p==q. This is what whoever-it-was meant when he said that the first form could fail if a==b. He did not mean `if the values are equal', he meant `if the variables are identical'. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris