comma operator

Dave Jones djones at megatest.UUCP
Sat Jan 23 10:48:21 AEST 1988


in article <2382 at ihuxv.ATT.COM>, rck at ihuxv.ATT.COM (R. C. Kukuk) says:
> 
> In article <7137 at brl-smoke.ARPA>, gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
>> In article <3887 at sigi.Colorado.EDU> swarbric at 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.
> 
> 
> Re: Another discussion in this news group --
> 
> Note that I said "a == b"; not "a = b". :-)
> 
> Ron Kukuk
> AT&T Bell Labs

I think some clarification is in order:  What Ron means is that

  swap(X,X)

will not work.  Sets X to 0 always.

  { int a; int b; a = 5; b = 5; swap(a,b); }

works just fine.



		Dave Jones
		Megatest Corp.



More information about the Comp.lang.c mailing list