Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!lll-crg!lll-lcc!qantel!hplabs!tektronix!uw-beaver!ssc-vax!uvicctr!sbanner1 From: sbanner1@uvicctr.UUCP (sbanner1) Newsgroups: net.lang.c Subject: Re: SWAP macro Message-ID: <174@uvicctr.UUCP> Date: Wed, 25-Jun-86 12:42:22 EDT Article-I.D.: uvicctr.174 Posted: Wed Jun 25 12:42:22 1986 Date-Received: Mon, 30-Jun-86 05:10:37 EDT References: <1577@brl-smoke.ARPA> Reply-To: sbanner1@uvicctr.UUCP () Organization: University of Victoria, Victoria B.C. Canada Lines: 32 In article <1577@brl-smoke.ARPA> Schauble@MIT-MULTICS.ARPA (Paul Schauble) writes: >I've gotten lots of respones to my request for a form of the macro that >would make > swap(*a++, *b++); > work. Almost all of them missed the point. The swap requires a >temporary. Generating that temporary requires knowing the type. >Several of the solutions would work fine if *a and *b were int's, but I >never said that. > >Recall the my original message was posted as a justification for a >typeof macro, akin to sizeof. I find that the need to generate >temporaries in a macro is not uncommon. Unless one is willing to do a >different version of the macro for each type, you need a way to generate >a new variable of the same type as one of the macro args. The language >provides no way to do this. I don't think you were reading all of the replys too closely. While I can see the use of the 'typeof' operator [not macro], there is a relatively easy way to do this, as atleast one person mentioned : #define swap(type, a, b) {type temp ... } Granted this can get a bit ugly if you will need three or four types, or if they are complex, but the facility *IS* there. Disclamer : The veiws expressed here may not be shared my anyone else on the face of the earth. S. John Banner !uw-beaver!uvicctr!sbanner1 :UUCP ccsjb@uvvm :Bitnet