Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!att!cbnewsl!dfp From: dfp@cbnewsl.ATT.COM (david.f.prosser) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <1579@cbnewsl.ATT.COM> Date: 22 Aug 89 22:10:23 GMT References: <8350@boring.cwi.nl> Reply-To: dfp@cbnewsl.ATT.COM (david.f.prosser) Organization: AT&T Bell Laboratories Lines: 19 In article <8350@boring.cwi.nl> tromp@piring.cwi.nl (John Tromp) writes: >How about > >x^=y^=x^=y; > >Avoids possible overflow problems and looks great in an >Obfuscated C Code entry too! This code need not do what was intended. In particular, it requires that "x" be assigned the result of the right-most ^= operation prior to its value being used in the left-most ^= operation. To eliminate this evaluation-order dependent behavior, some form of sequence point must be used between these two operations. For example y^=x^=y,x^=y; See section 3.3, and in particular footnote 31 (page 39) of the pANS. Dave Prosser ...not an official X3J11 answer...