
#include <stdio.h>
#include <string.h>

#include "arraycmp.h" /* from Listing 7 */

/*
 * arraycmp for int arrays
 */
#define intcf(i, j) ((i) - (j))
implement(arraycmp, int);

/*
 * arraycmp for double arrays
 */
int doublecf(double d, double e)
    {
    return d < e ? -1 : d == e ? 0 : 1;
    }
implement(arraycmp, double);

/*
 * arraycmp for const char * arrays
 */
typedef const char *str;
#define strcf(s, t) strcmp((s), (t))
implement(arraycmp, str);

/*
 * Sample calls to arraycmp...
 */
#define DIM(a) (sizeof(a) / sizeof(a[0]))

int a[] = {1, 2, 3, 4, -5};
int b[] = {1, 2, 3, 4, 4};

double f[] = {1, 2, 3, 4, 5};
double g[] = {1, 2, 3, 3, 4};

const char *s[] = {"123", "456", "789"};
const char *t[] = {"123", "789", "456"};

int main(void)
    {
    printf("a vs. b = %d\n",
        arraycmp(int)(a, b, DIM(a)-1));
    printf("a vs. b = %d\n",
        arraycmp(int)(a, b, DIM(a)));
    printf("f vs. g = %d\n",
        arraycmp(double)(f, g, DIM(f)));
    printf("s vs. t = %d\n",
        arraycmp(str)(s, t, DIM(s)));
    return 0;
    }

