Function pointers are especially handy when you want to perform a type of "overloading" in C, i.e. you may have 3 functions all defined as:
Code:
int foo(int a, int b);
int bar(int a, int b);
int fred(int a, int b);
Then you could define a function pointer:
Code:
int (*myfunc)(int, int);
and have a logic branch (such as a switch statement) appropriately assign the pointer depending on what command was issued:
Code:
switch(command_id){
case CMD1: myfunc = foo; break;
case CMD2: myfunc = bar; break;
case CMD3: myfunc = fred; break;
...
}
Then you could call myfunc(x, y) which will call the correct function for you. However, since all of your functions have different prototypes, I don't think function pointers will be very useful in this case. If you *really* wanted to use function pointers you could push the issue by prototyping all your functions as "void foo(void *)" and use the argument as a generic variable list. But I think in this case, since each function has its own varying set of arguments, you'd have to check the type and number of arguments anyways before trying to call the function, so you're better of with just a simple selection algorithm, i.e.:
Code:
switch(command_id){
case CMD1: aaa(x); break;
case CMD2: bbb(x, y, z); break;
case CMD3: ccc(); break;
...
}