I'm attempting to write a function to compare two arrays of pointers to see if they are the same. I'd like to use the function on any array of pointers, i.e. regardless of what the pointers point to - I'm just interested in equality of the pointers themselves
I've written this:
/**
* Return true if arrays (of type ptr to ptr) are equal
*/
bool ptr_array_eq(const void **x, const void **y, size_t n)
{
size_t i;
for (i=0; i<n; i++) {
if (x[i] != y[i]) {
return false;
}
}
return true;
}
my unit-test looks like this:
void testPTR_ARRAY_EQ(void)
{
Mode *m1, *m2, *m3, *m4, *m5, *m6;
Mode *a[] = {m1, m2, m3, m4, m5};
Mode *b[] = {m1, m2, m3, m4, m5};
Mode *c[] = {m2, m3, m4, m5, m6};
Mode *d[] = {m1, m3, m4, m5, m6};
CU_ASSERT(ptr_array_eq(a, a, 4));
CU_ASSERT(ptr_array_eq(a, b, 4));
CU_ASSERT(! ptr_array_eq(a, c, 4));
CU_ASSERT(! ptr_array_eq(a, d, 4));
}
but when i compile i get the following warnings (not errors):
test_utility.c: In function ‘testPTR_ARRAY_EQ’:
test_utility.c:648:5: warning: passing argument 1 of ‘ptr_array_eq’ from incompatible pointer type [enabled by default]
../src/glamdring2.h:327:6: note: expected ‘const void **’ but argument is of type ‘struct Mode **’
with the compiler complaining that in my unit-test the types I'm using don't match the function prototype
But I'm not really interested in the underlying type, only the pointer to it. Should I:
- a) just ignore the warnings
- b) rewrite the function in a way to make the compiler not issue warnings
- c) do some cast of the incoming pointers
- d) accept that C doesn't like the idea of not knowing the underlying type and re-write the function for each type of pointer I might encounter