4 ms·
No, in this context (a qsort() comparison callback) I'm talking about using casts to access the values to compare. Here's how I would have written it, without
by unwind 4y ago
No, in this context (a qsort() comparison callback) I'm talking about using casts to access the values to compare.
Here's how I would have written it, without memcpy():
static int cmp_double(const void *va, const void *vb)
{
const double a = *(const double *) va, b = *(const double *) vb;
return a < b ? -1 : a > b;
}
I know you can't "jump types", but this doesn't, since qsort() is passing pointers to doubles and we're just getting them back.
Edit: missed const:s in function body oops.