title: C [-Wincompatible-pointer-types] how to cast
body: <p>my code: <a href="https://godbolt.org/z/de7fbdjh7" rel="nofollow noreferrer">https://godbolt.org/z/de7fbdjh7</a></p>
  <p>code from source: <a href="https://stackoverflow.com/a/49072888/15603477">https://stackoverflow.com/a/49072888/15603477</a><br />
  Almost exact the same.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct 
  {
      int iValue;
      int kValue;
      char label[6];
  } my_data;
  
  int cmp_mydata_ivalue(my_data* item1 , my_data* item2 )
  {
      if(item1-&gt;iValue &lt; item2-&gt;iValue) return -1;
      if(item1-&gt;iValue &gt; item2-&gt;iValue) return 1;
      return 0;
  }
  
  int main(void){
      my_data datalist[256] = {0}; 
      {
          int i;
          for(i = 0;i&lt;20;i++){
              datalist[i].iValue = i+100;
              datalist[i].kValue = i+1000;
              sprintf(datalist[i].label,&quot;%2.2d&quot;, i+10);
          }
      }
      printf(&quot;new line\n&quot;);
      {
          my_data srchitem = {105,1018,&quot;13&quot;}; 
          
          my_data *foundItem = (my_data*) bsearch(&amp;srchitem, datalist,20, sizeof(my_data),cmp_mydata_ivalue);
          bsearch_results(&amp;srchitem, foundItem);
      }
  }
  </code></pre>
  <p>The same question asked many times. But I don't know how to cast it.<br />
  error code:</p>
  <pre><code>*callback1.c: In function ‘main’:
  callback1.c:58:89: warning: passing argument 5 of ‘bsearch’ from incompatible pointer type [-Wincompatible-pointer-types]
     58 |         my_data *foundItem = (my_data*) bsearch(&amp;srchitem, datalist,20, sizeof(my_data),cmp_mydata_ivalue);
        |                                                                                         ^~~~~~~~~~~~~~~~~
        |                                                                                         |
        |                                                                                         int (*)(my_data *, my_data *) {aka int (*)(struct &lt;anonymous&gt; *, struct &lt;anonymous&gt; *)}*
  </code></pre>
  <p>One way to try to use gcc option to supress the error. Another way is somewhere I need to cast. But now i don't know how to cast.</p>
  <p>Tutorial I found so far: <a href="https://www.tutorialspoint.com/c_standard_library/c_function_bsearch.htm" rel="nofollow noreferrer">https://www.tutorialspoint.com/c_standard_library/c_function_bsearch.htm</a></p>