core.stdc.stdlib._compare_fp_t and qsort

Seb seb at wilzba.ch
Mon Mar 12 03:13:08 UTC 2018


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

Out of interest: I wonder what's your usecase for using qsort. Or 
in other words: why you can't use the high-level 
std.algorithm.sorting.sort?


More information about the Digitalmars-d-learn mailing list