[Vala] sort (GLib.CompareFunc compare_func) C-compiler warning



When I try to compile the following simple program:

public int compare_test (void* a, void* b) {
  return 0;
}

public int main (string[] argv) {
  List <int> list = new List <int> ();
  list.append (3);
  list.append (12);
  list.append (8);
  list.sort (compare_test);
  return 0;
}

The Vala code compiles, but I get a warning from the C-compiler:

listsort.c: In function ‘_main’:
listsort.c:28: warning: passing argument 2 of ‘g_list_sort’ from incompatible pointer type

I can fix it by letting Vala generate C-code, then changing void* in the C-code to gcoinstpointer. If I do 
that the C-code compiles without warnings. However, if I change void* to something else in the Vala-code, it 
won't compile, giving this error:

listsort.vala:10.14-10.25: error: Argument 1: Cannot convert from `compare_test' to `GLib.CompareFunc'
  list.sort (compare_test);
             ^^^^^^^^^^^^

Am I doing something wrong?







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