/** * swap.c - the standard C swap routine. */ #include #include void swap (int *ap, int *bp) { int temp = *ap; *ap = *bp; *bp = temp; } // swap #ifdef UNIT_TEST int errors; void utest_swap () { int x = 1; int y = 2; swap (&x, &y); if ((x != 2) || (y != 1)) { ++errors; printf ("Failed to correctly swap x and y.\n"); } x = 0; swap (&x, &x); if (x != 0) { ++errors; printf ("Failed to correctly swap x with itself.\n"); } } // utest_swap int main () { utest_swap (); if (errors) printf ("%d errors encountered.\n", errors); return errors; } // main () #endif // UNIT_TEST