in reply to Re^3: Pass an "extra' variable to Find::File subroutine
in thread Pass an "extra' variable to Find::File subroutine
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Pass an "extra' variable to Find::File subroutine
by ikegami (Patriarch) on Jun 22, 2010 at 17:16 UTC |