Generic Swap
Peter Adams Whipple
whipple at sun.udel.edu
Tue Jun 12 01:11:02 AEST 1990
In article <1990Jun11.133729.6575 at cs.utk.edu> wozniak at utkux1.utk.edu (Bryon Lape) writes:
>
> Recently I tried to write a generic swap routine using void
>pointers, but it did not work. Below is an example:
[stuff deleted]
>generic_swap(void *, void *)
>{
> void *temp;
>
> temp = b;
> b = a;
> a = temp;
>}
You are swapping the pointer (which are local values) instead of
swapping the values (*a and *b). If you can use *a, *b, and *temp, the
routine will work as expected. Off-hand, I don't remember if you can
dereference a void *.
-- Peter
More information about the Comp.lang.c
mailing list