[Vala] Sorting an array of instances.


I've got problems sorting an array of instances. Take the following

class Foo
        public float val;

static int cmp_foo(void* a, void* b)
        return ((Foo*)a)->val - ((Foo*)b)->val < 0 ? -1 : 1;

void main(string[] args)
        Foo[] fs = new Foo[10];
        for( int i = 0 ; i < fs.length ; i++ )
                fs[i] = new Foo();
                fs[i].val = (float) Random.next_double();

        Posix.qsort( fs, fs.length, sizeof(Foo), cmp_foo );

        foreach( Foo f in fs ) message("%.4f", f.val);


This code does not sort the array fs.
If you take an struct instead of an array everything works as expected.

Does someone know why this happens? 


Attachment: smime.p7s
Description: S/MIME cryptographic signature

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