title: How do I pass a pointer to a c function in Cython?
body: <p>I'm trying call <code>qsort</code> in Cython with a custom compare function but I don't understand how to pass the function reference.  First, I have a struct:</p>
  
  <pre><code>cdef struct Pair:
      int i,j
      float h
  </code></pre>
  
  <p>The compare function sorts by <code>h</code>:    </p>
  
  <pre><code>cdef int compare(const_void *a, const_void *b):
      cdef float v = ((&lt;Pair*&gt;a)).h-((&lt;Pair*&gt;b)).h
      if v &lt; 0: return -1
      if v &gt; 0: return 1
      return 0
  </code></pre>
  
  <p>This is the part I'm having trouble with:</p>
  
  <pre><code>    cdef Pair[5] pa
      for i in range(5):
          pa[i].i = i;
          pa[i].j = i*2;
          pa[i].h = i*.5;
      qsort(pa,5,sizeof(Pair),compare)
  </code></pre>
  
  <p>The last line won't compile and generates this error which I believe is related to the fact that I can't figure out how to pass <code>compare</code> as a reference to <code>qsort</code>:</p>
  
  <pre><code>Cannot assign type 'int (const_void *, const_void *)' to 'int (*)(const_void *, const_void *) nogil'
  </code></pre>