Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!dcl-cs!strath-cs!allan From: allan@cs.strath.ac.uk (Allan Black) Newsgroups: net.lang.c Subject: Re: swap() macro Message-ID: <193@stracs.cs.strath.ac.uk> Date: Fri, 20-Jun-86 13:20:22 EDT Article-I.D.: stracs.193 Posted: Fri Jun 20 13:20:22 1986 Date-Received: Mon, 23-Jun-86 03:32:29 EDT References: <1201@brl-smoke.ARPA> Reply-To: allan@cs.strath.ac.uk (Allan Black) Organization: Department of Computer Science at Strathclyde University, UK. Lines: 21 In article <1201@brl-smoke.ARPA> Schauble@MIT-MULTICS.ARPA writes: >Can someone construct a version that makes > int *a, *b; > swap (*a++,*b++); >work right? #define swap(p,q) {int *x = &(p), *y = &(q); int z = *x; *x = *y; *y = z;} This will only work for type 'int'; if you want to make it more general, try something like: {long *x = (long)(&(p)) etc. But be careful with something like that - there's no typechecking, so you can easily mix pointers up, with disastrous results! -- UUCP: ...!seismo!mcvax!ukc!strath-cs!allan DARPA: allan%cs.strath.ac.uk@ucl-cs JANET: allan@uk.ac.strath.cs "This doesn't seem to be working, sir!" "Yes, but I was trying to ignore it so that YOU wouldn't look stupid!" -- Monty Python's Flying Circus