swap() macro

Gregory Smith greg at utcsri.UUCP
Sat Jun 21 01:38:24 AEST 1986


In article <1201 at brl-smoke.ARPA> Schauble at MIT-MULTICS.ARPA (Paul Schauble) writes:
>Can someone construct a version that makes
>
>    int *a, *b;
>    swap (*a++,*b++);
>
>work right?
>
#define swap( a,b ) { int *p1,*p2,t;\
	p1= &(a); p2= &(b); t= *p1;*p1= *p2;*p2=t;}

No, it isn't pretty.
how about:

#define swap(a,b) fswap(&(a),&(b))
fswap(a,b) int *a,*b;
{	etc.


-- 
"Shades of scorpions! Daedalus has vanished ..... Great Zeus, my ring!"
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg



More information about the Comp.lang.c mailing list