swap() macro

Mark Biggar markb at sdcrdcf.UUCP
Wed Jun 25 07:02:06 AEST 1986


In article <3007 at utcsri.UUCP> greg at utcsri.UUCP (Gregory Smith) writes:
>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.

BOTH of these die a horrible death if either argument is declared
"register".

Mark Biggar
{allegra,burdvax,cbosgd,hplabs,ihnp4,akgua,sdcsvax}!sdcrdcf!markb



More information about the Comp.lang.c mailing list