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

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

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

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

/*
 * arraycmp for const char * arrays
 */
typedef const char *str;
#define strcf(s, t) strcmp((s), (t))
arraycmp_implement(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(a, b, DIM(a)-1));
    printf("a vs. b = %d\n", arraycmp(a, b, DIM(a)));
    printf("f vs. g = %d\n", arraycmp(f, g, DIM(f)));
    printf("s vs. t = %d\n", arraycmp(s, t, DIM(s)));
    return 0;
    }

