Generic Swap

Bryon Lape wozniak at utkux1.utk.edu
Mon Jun 11 23:37:29 AEST 1990


	Recently I tried to write a generic swap routine using void
pointers, but it did not work.  Below is an example:

#include<stdio.h>

void generic_swap(void *, void *);

main()
{
   short int x=4, y=50;

   printf("\n%d  %d", x ,y);
   generic_swap(&x, &y);
   printf("\n%d  %d", x, y);
}

generic_swap(void *, void *)
{
   void *temp;

   temp = b;
   b = a;
   a = temp;
}

	I ran this in Quick C 2.0 and the values DID exchange within the
function, but not on the outside.  Anyone know what might be wrong?


-bryon lape-



More information about the Comp.lang.c mailing list