Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!husc6!harvard!caip!sri-spam!nike!styx!lll-crg!gymble!umcp-cs!seismo!mcvax!cernvax!mnl From: mnl@cernvax.UUCP (mnl) Newsgroups: net.lang.c Subject: Re: Boolean Operators Slighted in C (really swap with XOR) Message-ID: <314@cernvax.UUCP> Date: Thu, 15-May-86 22:11:08 EDT Article-I.D.: cernvax.314 Posted: Thu May 15 22:11:08 1986 Date-Received: Sat, 17-May-86 04:13:12 EDT References: <602@brl-smoke.ARPA> <2741@utcsri.UUCP> Reply-To: mnl@cernvax.UUCP (Mark Nelson) Organization: CERN, Geneva/Switzerland Lines: 32 In article <2741@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) writes: >In article <602@brl-smoke.ARPA> rbj@icst-cmr (Root Boy Jim) writes: > >>3) Exchange operator. This has probably been discussed before, so pardon >> me if I blunder into that pit. BUT, DMR has stated that one of >> the reasons that exponentiation was left out was because no >> (or few, if any) machine could do it inline, and therefore >> all the compiler would be doing is a function call anyway. >> By the same reasoning, exchange CAN be done efficiently by >> some machines, and the hack of a temporary variable and >> three assignments is a rather stale idiom. The three >> statement XOR trick avoids the temporary, at the expense >> of execution time and clarity. >> >Good stuff. Even machines without an EXG can use a scratch register, which >is better than using a user-supplied temp. >What, by the way, is the XOR trick? > To swap the contents of A and B (no particular language): A = A XOR B B = A XOR B A = A XOR B On some machines, assuming A and B are in registers, this won't take any more time than the normal three assignments using a temporary. -- Mark Nelson mnl@cernvax.bitnet or ...!seismo!mcvax!cernvax!mnl If the ACM had a sub-group for naturalists, would it be ACM SIGnature?