Would I?
It's a common pattern in C libraries to pass a void pointer to callbacks, and allow the caller of the library to hand in a pointer which is then passed on to the callback.
And that's a rather sane design in a language without closures, because otherwise the the callback can't obtain additional information about the caller (except for globals, which makes rekursive calls dangerous to impossible).
Other popular design decision include a hidden, global state variable (same problem with reentrancy), or omitting callbacks altogether (might work for a directory traversal library like File::Find, but would be exceptionally painful for a GUI toolkit). |