Re: [Vala] Sorting a GLib.List<string>
- From: Didier 'Ptitjes' <ptitjes free fr>
- To: Magnus Therning <magnus therning org>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Sorting a GLib.List<string>
- Date: Sat, 26 Sep 2009 17:36:54 +0200
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)
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:
* transparent uses of standard compare funcs for primitive, string and
object types
* possibility to make your classes inherit Comparable<G>
* rid of equal functions at List construction time for primitive,
string and object types
Best regards, Didier.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]