Having already checked What is a 'thunk'?, I'm still not sure why the extra argument passed to the re-entrant qsort_r
would be called thunk
.
Eg: (BSD style qsort_r
)
void qsort_r(void *base_, size_t nmemb, size_t size, void *thunk,
int (*compar)(void *, const void *, const void *));
To be clear, I know what the argument is for, and how to use it, just not why its called thunk
(in the BSD's qsort_r
at least).
The name seems to be from the original proposed implementation by Diomidis Spinellis
The implementation shows that it is just used as an opaque data block, passed through
qsort_r
and back to your compare function.It seems to somewhat match the 3rd concept in this answer.
But really, it just seems like a misleading name. I usually think of thunks as containing blocks of code. In this case it is just a container for context.