title: Why can `qsort` be called with a compare function with the wrong signature and compile has no warnings
body: <p>I was working on consolidating a code base (moving a <code>qsort</code> <code>compar</code> function to a new header /library so that it could be shared without being copy/pasta) and noticed something strange in the process.</p>
  <p>Here is a demonstrative listing:</p>
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  
   /** One record has three fields.
   * Each field contains a NULL terminated string of length at most 7 characters. */
  typedef char Record[3][8];
  
  int main(void)
  {
      Record database[5] = {0};
  
      strcpy(database[0][0], &quot;ZING&quot;);
      strcpy(database[0][1], &quot;BOP&quot;);
      strcpy(database[0][2], &quot;POW&quot;);
  
      strcpy(database[1][0], &quot;FIDDLY&quot;);
      strcpy(database[1][1], &quot;ECHO&quot;);
      strcpy(database[1][2], &quot;ZOOOM&quot;);
  
      strcpy(database[2][0], &quot;AH&quot;);
      strcpy(database[2][1], &quot;AAAAA&quot;);
      strcpy(database[2][2], &quot;AH&quot;);
  
      strcpy(database[3][0], &quot;BO&quot;);
      strcpy(database[3][1], &quot;DELTA&quot;);
      strcpy(database[3][2], &quot;FO&quot;);
  
      strcpy(database[4][0], &quot;FRRING&quot;);
      strcpy(database[4][1], &quot;CRASH&quot;);
      strcpy(database[4][2], &quot;FOO&quot;);
  
      //(gdb) ptype record_compare_field_1
      //type = int (char (*)[8], char (*)[8])
      int record_compare_field_1();
      qsort(database, 5, sizeof(Record), record_compare_field_1);
      for (int i = 0; i &lt; 5; i++){
          printf(&quot;%s\t%s\t%s\n&quot;, database[i][0], database[i][1], database[i][2]);
      }
  }
  
  /* Compares Records at field one. */
  int record_compare_field_1(Record rowA, Record rowB)
  {
      return strcmp(rowA[1], rowB[1]);
  }
  </code></pre>
  <p>Compile and run:</p>
  <pre><code>$ gcc -Wall main.c
  $ ./a.out
  AH      AAAAA   AH
  ZING    BOP     POW
  FRRING  CRASH   FOO
  BO      DELTA   FO
  FIDDLY  ECHO    ZOOOM
  </code></pre>
  <p>It's surprising to me that:</p>
  <ul>
  <li>The compiler has no warnings since the signature of the <code>compar</code> function passed to quick sort does not have the prescribed function signature <code>int (*compar)(const void *, const void *)</code>. Even in <code>gdb</code>, when I run <code>ptype record_compare_field_1</code>, it looks like the signature does not contain <code>const *void</code>.</li>
  <li>The output is <strong>somehow</strong> correct? (Sorted based on field one (zero-indexed) results in <code>AAAAA, BOP, CRASH, DELTA, ECHO</code>.</li>
  </ul>
  <p>The questions are:</p>
  <ul>
  <li>Why/how does this work? Is this an old-school way of doing this?</li>
  <li>If I wanted to change the <code>qsort</code> <code>compar</code> function in use to use the proper signature, how would I do that (I been struggling trying to come up with the proper casts)?</li>
  </ul>
  <p>Thank you!</p>