3

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).

ideasman42
  • 42,413
  • 44
  • 197
  • 320
  • Yeah, I always wonder why it is not just called "Fred". Just kidding. I checked for a translation, but did not find a good answer why they actually choose that name. I'd say just accept and do not think about it:-) – too honest for this site Jun 11 '15 at 15:37
  • 2
    @Olaf, I mainly asked because was writing my own sorting function and went to add `thunk` arg... when writing own API's I like to know reasons behind naming. – ideasman42 Jun 11 '15 at 15:38
  • I like that attitude! That information was missing actually. However, you can choose the name freely as you know. Just call it "current_state" or so. I think "thunk" might just sound crispier. – too honest for this site Jun 11 '15 at 15:46

1 Answers1

4

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.

a mapping of machine data from one system-specific form to another, usually for compatibility reasons

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.

Community
  • 1
  • 1
AShelly
  • 34,686
  • 15
  • 91
  • 152