I'm not sure I have the best title for this question, feel free to improve.
If I have
typedef void (*VoidFunction)(void);
And then a family of functions that fit this type, I could write a sort of "transaction" wrapper function that looked something like:
void doTransaction(VoidFunction function)
{
doSomePreambleWork();
function();
doSomePostambleWork();
}
If I had a family of functions that took single int arguments, I could wash-rinse-repeat:
typedef void (*VoidOneIntFunction)(int a);
void doTransactionOneInt(VoidFunctionOneInt function, int a)
{
doSomePreambleWork();
function(a);
doSomePostambleWork();
}
Leaving the issue of return types (iow, assuming a void return type), is it possible to genericize this pattern, so that I only have to do write one wrapper function, something like:
// ????? I'm not sure how i'd type the passed function
void doTransactionGeneric(void * function, ...)
{
doSomePreambleWork();
function(); // ????? and i don't know how i'd go about calling it...
doSomePostambleWork();
}
<stdarg.h>header. The solution is to use a variable argument list.