On Sat, Sep 26, 2009 at 05:36:54PM +0200, Didier 'Ptitjes' wrote:
> Hi Magnus,
> 
> Magnus Therning wrote:
> >What function should I use to sort a list of strings to avoid the
> >compiler warning I get with strcmp:
> >
> >  ...
> >  my_list.sort( strcmp );
> >  ...
> >
> >Test.vala:60: warning: passing argument 2 of ‘g_list_sort’ from
> >incompatible pointer type
> >/usr/include/glib-2.0/glib/glist.h:101: note: expected
> >‘GCompareFunc’ but argument is of type ‘int (*)(const char *,
> >const char *)’
> 
> You have to explicitly cast it to CompareFunc. Indeed, the
> GLib.strcmp is just a convenience binding around stdlib's strcmp,
> and they appear to not have the exact same signatures. IIRC those
> are:
> 
> int strcmp (void* a, void* b)
> gint GCompareFunc (gconstpointer, gconstpointer)
It might more sense to tell Vala to cast it to GCompareFunc in the
C code, as it is already listed in the VAPI as CompareFunc and casting
a CompareFunc to its own type should really not be needed.

> 
> However, I would suggest you to use libgee-0.5 which is expected to
> be (finally) released on Monday September 29, 2009 (or master from
> git).
> 
> Gee.List<G>.sort uses an efficient TimSort algorithm, and for free you get:
Sounds great, this will finally allow APT2 to read a sorted list of
files from a directory.


-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to