Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Obfuscated SWAP: not portable! Message-ID: <1134@virtech.UUCP> Date: 6 Sep 89 14:01:13 GMT References: <784@skye.ed.ac.uk> <1267@levels.sait.edu.au> <149@cpsolv.UUCP> <1400@levels.sait.edu.au> Organization: Virtual Technologies Inc Lines: 35 In article <1400@levels.sait.edu.au>, CCDN@levels.sait.edu.au (DAVID NEWALL) writes: > In article <149@cpsolv.UUCP>, rhg@cpsolv.UUCP (Richard H. Gumpertz) writes: > > The exchange of x and y that has been under discussion: > > x ^= y ^= x ^= y > > is non-portable because it depends on right-to-left evaluation which is NOT > > specified in the C standard. > > I think it is specified. (Perhaps it depends on whose standard you follow?) > > K&R I, page 19: > "The line > nl = nw = nc = 0; > sets all three variables to zero. This is not a special case, but a > consequence of the fact that an assignment has a value and assignments > associate right to left." But, you cannot know what the value of x is at the far left of the equation prior to evaluating the "^=". It may be the original value of x, or it may be the latest value of x (modified by the right hand side of the equation. As far as I know, there is no specification as to when the x will be evaluated. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+