Я конечно просто туплю, но никак не могу найти пример использования функции qsort_with_data
Пока сделал так(всё работает):
static int greater (void* a, void* b)
{
int arg1 = * (int*)a;
int arg2 = * (int*)b;
if (arg1 < arg2) return 1;
if (arg1 > arg2) return -1;
return 0;
}
void some_func(int[] copy_input)
{
Posix.qsort(copy_input, copy_input.length, sizeof(int), greater);
....
}
Попробовал использовать её так:
static int greater_int (int arg1, int arg2)
{
if (arg1 < arg2) return 1;
if (arg1 > arg2) return -1;
return 0;
}
void some_func(int[] copy_input)
{
qsort_with_data<int>(copy_input, sizeof(int), greater_int);
....
}
Получаю
/usr/share/vala-0.36/vapi/glib-2.0.vapi:5714:11: runtime error: load of misaligned address 0x60200000ea74 for type 'const <unknown> *', which requires 8 byte alignment
0x60200000ea74: note: pointer points here
0e 00 00 00 0e 00 00 00 0e 00 00 00 0e 00 00 00 03 00 00 00 00 00 00 02 10 00 00 00 01 00 00 54
^
/usr/share/vala-0.36/vapi/glib-2.0.vapi:5714:11: runtime error: load of misaligned address 0x60200000ea74 for type 'const <unknown> *', which requires 8 byte alignment
0x60200000ea74: note: pointer points here
0e 00 00 00 0e 00 00 00 0e 00 00 00 0e 00 00 00 03 00 00 00 00 00 00 02 10 00 00 00 01 00 00 54
P.S. на valadoc смотрел, к сожалению именно к этой функции нет примера:
https://valadoc.org/glib-2.0/GLib.qsort_with_data.html
Хотя, например, к потокам есть объясняющий пример https://valadoc.org/glib-2.0/GLib.Thread.html