C comparison of array of pointers -


I am trying to write a function to compare two arrays of pointers to see if they I would like to use functions on any array of signals, that is what the indicators indicate - I am only interested in the similarity of the indicator.

I have written it: < Code> / ** * If true, array (type PTR to PTR) is equal to * / bool ptr_array_ Eq (conduit void ** x, const void ** y, size_t n) {size_t i; For (i = 0; i & lt; n; i ++) {if (x [i]! = Y [i]) {return false; True} true; }

My unit test looks like this:

  zero testPTR_ARRAY_EQ (zero) {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: "testPTR_ARRAY_EQ?" ??: test_utility.c: 648: 5: WARNING: 1 argument of passing ??? Ptr_array_eqâ ???? Inconsistent indicator type [enabled by default] ./src/glamdring2.h:327:6: Note: Expected "Cant Align" ** But there is a type of logic type; Structure mode ** one ????   

The compiler is complaining that the type I am using in my unit-test does not match the function prototype

but I'm not really interested Has the underlying type, only the pointer to it.

  • a)
  • c)
  • d) Do not allow the console to issue warnings
  • b) I agree that C does not know the underlying type and does not like the idea of ​​rewriting the function for each type of indicator. I < const zero *
    < / Div>

    Required for your function (an indicator of the first element) / Code>.

    You are trying to pass it to an array of mode * (an indicator of the first element).

    This is not allowed in C, because (among other reasons) it is not even guaranteed from the C standard that zero * and mode * If there are similar shapes, language does not mistakenly treat such programs as an array, as if it is an array of others.

    In relation to implementation-specific specifications, which they are very much in implementation, you can use memcmp to compare arrays.

  • Comments