I\'m trying to swap objects for a homework problem that uses void pointers to swap objects. The declaration of my function has to be:
void swap(void *a, voi
First of all, note that any changes to the pointers inside the function won't be propagated to outside the function. So you're going to have to move memory around.
The easiest way to do that is with memcpy
- allocate a buffer on the stack, memcpy
the appropriate size from a
into it, memcpy
from b
to a
, and one last memcpy
from temp into b
.