Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: comma operator Message-ID: <564@cresswell.quintus.UUCP> Date: 23 Jan 88 03:45:24 GMT References: <3819@sigi.Colorado.EDU> <5080013@hpfcdc.HP.COM> <7120@brl-smoke.ARPA> <3476@ihlpf.ATT.COM> Organization: Quintus Computer Systems, Mountain View, CA Lines: 14 In article <3476@ihlpf.ATT.COM>, nevin1@ihlpf.ATT.COM (00704A-Liber) writes: > In article <2382@ihuxv.ATT.COM> rck@ihuxv.ATT.COM (R. C. Kukuk) writes: > >> In article <3887@sigi.Colorado.EDU> swarbric@tramp.Colorado.EDU (SWARBRICK FRANCIS JOHN) writes: > >> >#define swap(a,b) ((a) = ((b) = ((a) = (a) ^ (b)) ^ (b)) ^ (a)) > >> >He says it will work for anything (int, char *, etc.). > > > >This oldie fails when a == b. Why? Think about it. > > I did. I still don't see why it fails. > swap(a, a); sets a to 0, whatever its previous value was. If you do swap(*p, *q); it can easily happen that p==q, in which case you get this problem.