The second argument of a CompareFunc List sorting function does not seem to get
sent to the function at all. For integer sorting, 0 is sent; for object
sorting,
null is sent.
For example, in the following code, the output from sort_function always says
that item 2 is 0 when in fact it should never be 0. And the list is not sorted
correctly.
public class Main
{
public static void main (string[] args)
{
var list = new List<int>();
list.append(3);
list.append(2);
list.append(1);
list.append(4);
foreach (int i in list)
print ("list item = " + i.to_string() + "\n");
list.sort((CompareFunc) sort_function);
foreach (int i in list)
print ("list item = " + i.to_string() + "\n");
}
public int sort_function(int item1, int item2) {
print ("item 1 is " + item1.to_string ()
+ " and item 2 is " + item2.to_string () + "\n" );
if (item1 < item2)
return -1;
if (item1 == item2)
return 0;
return 1;
}
}
Example output is:
list item = 3
list item = 2
list item = 1
list item = 4
item 1 is 4 and item 2 is 0
item 1 is 2 and item 2 is 0
item 1 is 4 and item 2 is 0
item 1 is 1 and item 2 is 0
list item = 4
list item = 1
list item = 2
list item = 3
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list