Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxb!mhuxr!ulysses!allegra!mit-eddie!godot!harvard!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: swapping variables Message-ID: <416@rlgvax.UUCP> Date: Mon, 4-Feb-85 23:56:05 EST Article-I.D.: rlgvax.416 Posted: Mon Feb 4 23:56:05 1985 Date-Received: Thu, 7-Feb-85 02:43:19 EST References: <8001@brl-tgr.ARPA> Organization: CCI Office Systems Group, Reston, VA Lines: 31 > > How often have you written: > > > > { register type t; > > > > t = a; > > a = b; > > b = t; > > } > Rarely. I use: `a ^= b; b ^= a; a ^= b;' Only worx for integer types. Also takez more cycles on most machines. An example: on the 68000, case 1 is move.l a,t # 32-bit ints move.l b,a move.l t,a case 2 is move.l b,d0 eor.l d0,a move.l a,d0 eor.l d0,b move.l b,d0 eor.l d0,a Cute, but not worth it. Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy