On Sunday, 11 March 2018 at 23:12:30 UTC, Joe wrote:
I'm getting a compiler error in a qsort() call as follows:
qsort(recs, num_recs, (Record *).sizeof, compar);
Record is a struct, recs is a fixed array of pointers to
Record's and num_recs is a size_t that holds the number of
valid records.
compar is this:
int compar(const void *p1, const void *p2)
{
import core.stdc.string : strcmp;
const Record **rp1 = cast(Record **)p1;
const Record **rp2 = cast(Record **)p2;
return strcmp((*rp1).name.ptr, (*rp2).name.ptr);
}
The error is: Error: function testd.compar (const(void*) p1,
const(void*) p2) is not callable using argument types ()
I don't quite understand what those parentheses mean: is it
implying "no arguments" and if so, where would one provide
arguments?
Joe
You have to pass a pointer to the function.
Otherwise it'll be a parenthsis-less call.
use : qsort(recs, num_recs, (Record *).sizeof, &compar);