I’m looking for something similar to C++’s boost::bind but in C. What I want is to be able to:
bound_function = bind(my_function, some_param);
and have:
bound_function(something);
execute
myfunction(some_param, something);
So basically, whatever is bound to the function pointer will always be passed as the first parameter to the function.
Is there any way to do this in C?
Don’t do this at home kids.
You couldn’t do it the way C++ does it, because in
boost::bind‘s case, a class is generated using TMP that holds the actual bound value.I’m not aware of any way to accomplish anything similar in C. Most C APIs with callbacks like this will pass around a
void *for your use to get around issues like this.