core.stdc.stdlib._compare_fp_t and qsort

Joe jma at freedomcircle.com
Sun Mar 18 19:01:11 UTC 2018


On Sunday, 18 March 2018 at 18:11:02 UTC, Dmitry Olshansky wrote:
> Well since recs is array of pointers this looks like a null 
> pointer in your data.
>
> The usual ways to fix that is either print stuff or poke around 
> in debugger to see if a Record* is null or .name is null.

The problem is that although the "recs" array is declared as 
having 10 pointers, not all pointers are used.  In the qsort 
case, the second argument limited the sort to just the first 
n_recs (valid) pointers. There doesn't seem to be a way to tell 
std.algorithm.sorting.sort to only look at part of the fixed 
array.

I managed to get it working by declaring a D dynamic array, 
appending n_recs pointers to it and using it as argument to sort. 
Unfortunately, I then had to copy from the dynamic array to the 
fixed array in order to continue using the latter. Any shortcuts 
around this?



More information about the Digitalmars-d-learn mailing list