What Maleficus is doing right now IS portable. As long as all the functions have identical arguments, storing them in the struct is perfectly doable.
Code:
typedef struct
{
int foo;
int (*fooFunc) (int *param1, int *param2);
int param1;
int param2;
} my_func_t;
Code:
// instancing
my_func_t *callerFunc;
callerFunc = new (my_func_t);
// filling in
callerFunc->fooFunc = myCoolFunc;
callerFunc->param1 = 14;
callerFunc->param2 = 22;
// calling
callerFunc->fooFunc (callerFunc->param1, callerFunc->param2);
This is 100% portable.
If you want to call funcs that have variable types of arguments instead, you can do something like this:
Code:
typedef struct
{
union
{
bool bparam;
char cparam;
long iparam;
float fparam;
long long lparam;
double dparam;
};
char param_type;
} param_t;
typedef struct
{
int foo;
int (*fooFunc) (int *param1, int *param2);
param_t params[256];
int param_count;
} my_func_t;
Code:
// instancing
my_func_t *callerFunc;
callerFunc = new (my_func_t);
// filling in
callerFunc->fooFunc = myCoolFunc;
callerFunc->params[0].fparam = 12.3456789f;
callerFunc->params[0].type = PARAM_FLOAT;
callerFunc->params[1].lparam = 24;
callerFunc->params[1].type = PARAM_LONG;
callerFunc->param_count = 2;
// calling
// HERE GOES DIRTY ASM CODE TO STACK UP THE ARGUMENTS AND CALL THE FUNCTION
of course THIS, will not be portable.