swap(x,y)

Wolfgang Deifel wolfgang at ruso.UUCP
Mon Aug 28 18:32:04 AEST 1989


pmaniac at walt.cc.utexas.edu (Noah Friedman) writes:

>void swap(double *x, double *y) 
>{
>    *x += *y;
>    *y = *x - *y;
>    *x -= *y;
>}

>func()
>{
> int a, b;

>    ...
>    swap((double *) &a, (double *) &b);
>    ...
>}

I think, this function never works right. If you cast the adress of
an integer to adress of double, you don't cast the int to double.
What you wanted to do is ( I think ), &((double)a) but this also
doesn't work, because (double)a is an r-value which has no adress.

--
Wolfgang Deifel
Dr. Ruff Software GmbH, 5100 Aachen, Juelicherstr. 65-67, W-Germany
uucp: ...!uunet{!mcvax}!unido!rwthinf!ruso!wolfgang - phone : +49 241 156038



More information about the Comp.lang.c mailing list