Hello, I've got problems sorting an array of instances. Take the following code: <code> 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); } </code> 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? Greetings fabian
Attachment:
smime.p7s
Description: S/MIME cryptographic signature