
On Fri, Nov 29, 2013 at 11:23:35AM +0100, Matthijs Möhlmann wrote:
Hello all, I'm not sure if this is possible at all, but let me explain:
It's not possible.
I have the following function signature: typedef int (*sasl_callback_ft)(void);
That function in question gets called with unknown amount of parameters (usually 3 or 4)
That doesn't quite make sense. That signature is for a function that takes exactly zero arguments, both in C and C++.
boost::function
callback = boost::bind(&admin::callback_fun, this, _1, _2, _3, _4); Obviously the compiler doesn't allow to assign callback to a sasl_callback_ft var sasl_callback_ft fun = callback;
Both boost::function and the return type of boost::bind are objects of a Callable type. They bear no relation to traditional function pointers except that you can call them with the same kind of syntax. A function pointer can be assigned a free function, a static member function or a stateless lambda. You may want to look into libraries that via code generation or other tricks produce a completely new function in memory, often called a "thunk" or a "trampoline", which forwards to the actual more complex callable. Another approach is to store state in some external/global/thread-local storage and assign a free function that forwards the call based on the stored state and any other state you can gleam from your library. Often, C-like APIs like the one you try to interact with tends to have a void* in the interface which you can use to tunnel the information needed to call the right thing. If this API doesn't have such a thing, you're in for a fun time. -- Lars Viklund | zao@acc.umu.se