什么是 'thunk'? (在可重入排序函数的上下文中,例如:qsort_r)

What is a 'thunk'? (in the context of re-entrant sort functions, eg: qsort_r)

已经检查过 What is a 'thunk'?,我仍然不确定为什么传递给重入者 qsort_r 的额外参数会被称为 thunk

例如:(BSD 风格 qsort_r

void qsort_r(void *base_, size_t nmemb, size_t size, void *thunk,
             int (*compar)(void *, const void *, const void *));

明确地说,我知道参数的用途以及如何使用它,只是不知道为什么它被称为 thunk(至少在 BSD 的 qsort_r 中)。

名字好像来自original proposed implementation by Diomidis Spinellis

implementation 表明它只是用作不透明数据块,通过 qsort_r 并返回到您的比较函数。

好像有点符合this answer中的第三个概念。

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

但实际上,这似乎是一个误导性的名称。我通常认为 thunk 包含代码块。在这种情况下,它只是上下文的容器。