Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: net.lang.c Subject: Re: swap() macro Message-ID: <444@mcgill-vision.UUCP> Date: Tue, 24-Jun-86 21:49:00 EDT Article-I.D.: mcgill-v.444 Posted: Tue Jun 24 21:49:00 1986 Date-Received: Fri, 27-Jun-86 05:16:00 EDT References: <1228@brl-smoke.ARPA> Organization: McGill University, Montreal Lines: 37 In article <1228@brl-smoke.ARPA>, rbj@icst-cmr (Root Boy Jim) quotes > Can someone construct a version that makes > int *a, *b; > swap (*a++,*b++); > work right? and writes > Probably not. In general, macros don't work on arguments that have side effects. How about the following, which assumes the arguments have addresses (no bitfields or register variables need apply). I would advise C portability purists to hit n; this code is pretty gross. #define swap(x,y) \ { register char *t1 = (char *)&(x); \ register char *t2 = (char *)&(y); \ register int n = sizeof((x)); \ register int i; \ for (i=0;i