I have a program in which te type of function to be used has to be different according to a string (the mode). Suppose i want the functions in extfunc to be initiated according to the value i write in some strings, that i have the following situation.
I have a number of functions
void f1_mod1(...)
{
//do domething
}
void f1_mod2(...)
{
//do something else
}
void f2_mod1(...)
{
//do something 2
}
void f2_mod2(...)
{
//do something 2
}
and I want them to be used according to some configurational strings fXn, where X = 1, 2, as in
void extfunc(...)
{
// ...
char *f1n = "mod1";
char *f2n = "mod2";
void (*__f1__)(), (*__f2__)();
__thefunctioniwouldlike(f1n, __f1__, f2n, __f2__);
// execute f1_mod1
__f1__(...);
// execute f2_mod2
__f2__(...);
}
where
void __thefunctioniwouldlike(char *f1n, void *__f1__, char *f2n, *__f2__)
{
if (strcmp(f1n, "mod1") == 0)
__f1__ = f1_mod1;
else if (strcmp(f1n, "mod2") == 0)
__f1__ = f1_mod2;
else
__f1__ = NULL;
if (strcmp(f2n, "mod1") == 0)
__f2__ = f2_mod1;
else if (strcmp(f1n, "mod2") == 0)
__f2__ = f2_mod2;
else
__f1__ = NULL;
}
is a function that takes the configurational strings and assign the function pointers to one of my functions above so that when they are called execute the assigned function.
For completeness:
fX_modX are the functions that take certain arguments and do different stuff both based on the mod variable fXn encoded in a string and __thefunctioniwouldlike is a function that takes as argument the pointers to functions to initiate them according to the value of strings fXn. How can i pass the pointer to pointers to void functions void (*__f1__)() so that in the end executing __fX__ in extfunc will execute fX_modY or fX_modY based on the assignment inside __thefunctioniwouldlike?
Thanks in advance.
...in function parameter lists in your examples, you don't actually mean that the functions involved are variadic, do you?