Re: [Vala] how to call extern function expecting function pointer?



> You should declare your delegate static...

Aha - I see.  I've now declared a static delegate, and Vala now generates the following C code:

  typedef gint (*CompareFunc) (void* a, void* b);
  static void qsort (void* base, gsize count, gsize size, CompareFunc f);

Unfortunately I still receive the same error message:

  top.c:41: error: conflicting types for ‘qsort’
  /usr/include/stdlib.h:689: error: previous declaration of ‘qsort’ was here

The problem seems to be that the library qsort expects a comparison function that takes const pointers:

  // in stdlib.h
  typedef int (*__compar_fn_t) (__const void *, __const void *);

So, then: is there an attribute I can apply so that Vala will generate a function prototype with const?  Or must I fall back on wrapping qsort() in a C function that's easier to call from Vala?

thanks!

adam

Thomas Chust wrote:
Adam Dingle schrieb:
  
[...]
So: is there some attribute I can apply to the extern declaration that
will cause Vala to generate a compatible function prototype? Or should I
instead write some C code to wrap qsort() into a C function which Vala
can call more easily? Thanks for any advice -
[...]
    

You should declare your delegate static, since qsort doesn't allow you
to pass a closure pointer through to the compare function. The signature
of the delegate function type and the qsort function declaration
generated by Vala should then be compatible with the C library.

cu,
Thomas

  



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]