I'm fairly sure that the original authors of this codebase wrote X11 code in C; this is because a) vast swaths of the C++ code are pretty much made of C-isms, with a few old comments describing conversion-from-C, and b) there are calls to
X*
and Xt*
functions in the code to handle various things at least some of which a library that wants to be cross-platform should probably not be trying to handle on its own. (Not all. But some.)So, given the frequency and consistency with which X11 uses a pair of "
return_type (*fp)(void *, other_stuff); void *arg;
" for callbacks to user code, you would think that the designers of this system would have the sense to do so themselves, instead of passing around pure function pointers (whose usual function-values, when invoked, go on to reference global data).This is another reason Boost.Function is the crowning jewel of the Boost libraries. By design, it functions as a drop-in replacement for those function pointers: I can just change them to
boost::function<return_type (other_stuff)> fp
, toss a nonce-closure in (although probably boost:bind
-constructed, unlike that example), and walk away unworried — everything that worked before will still compile and run properly.
No comments:
Post a Comment