Then it's clearly only half a solution.
The example I gave above should work fine in any language with first-class closures.
reply
_Thread_local struct { void *data; int (*compare)(const void *a, const void*, void*); } _qsort2_closure ; static int _qsort2_helper(const void *a, const void *b) { return _qsort2_closure.compare(a, b, _qsort2_closure.data); } void qsort2(void *base, size_t elements, size_t width, int (*compare)(const void *a, const void*, void*), void *userData) { _qsort2_closure.data = userData; _qsort2_closure.compare = compare; qsort(base, elements, width, _qsort2_helper); }
No I do not. It will reassigned next call.
> But again you are reinventing dynamic scoping
No. I’m not reinventing anything. I’m using the existing feature of thread local variables.
The usage of such is entirely an implementation detail of qsort2 with the exception of recursion.
Dynamic scoping typically refers to defining variables which have scope outside of their call stack. No usage of this API requires it.
Can you just try to learn something new?
Once again, the caller of the API does not declare any variables so there is no dynamic scoping.