Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!umcp-cs!cvl!umd5!zben From: zben@umd5.UUCP (Ben Cranston) Newsgroups: net.lang.c Subject: Re: swap() macro Message-ID: <1048@umd5.UUCP> Date: Tue, 24-Jun-86 14:11:13 EDT Article-I.D.: umd5.1048 Posted: Tue Jun 24 14:11:13 1986 Date-Received: Fri, 27-Jun-86 03:52:45 EDT References: <1201@brl-smoke.ARPA> <370@anasazi.UUCP> Reply-To: zben@umd5.UUCP (Ben Cranston) Organization: U of Md, CSC, College Park, Md Lines: 32 Summary: Why just one *? Paul Schauble asks: > Can someone construct a version that makes > int *a, *b; > swap (*a++,*b++); >> work right? Steve Villee replies: > #define swap(x, y) \ > if (1) \ > { \ > register int *xp, *yp, t; \ > xp = &(x); \ > yp = &(y); \ > t = *xp; \ > *xp = *yp; \ > *yp = t; \ > } \ > else and goes on to site some special cases in which the "if" implementation is a big win. Other examples have also been given. Since the original question was about swapping (int *)s, why do not the given examples involve (int **)s, i.e. pointers to pointers to ints? Nailing jelly to a tree again... -- umd5.UUCP <= {seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben Ben Cranston zben @ umd2.UMD.EDU Kingdom of Merryland Sperrows 1100/92 umd2.BITNET "via HASP with RSCS"