Let's see if I can explain what I would like to do (sorry for the inacuracy, I'm not a C expert).
I have a set of (similar) functions called depending on some value. Kind of (simplified):
The real situation is more complex obviously, but I hope it's clear enoughCode:int Func_0(int i) { ... return j; } int Func_1(int i) { ... return j; } ... int Func_n(int i) { ... return j; } ... for (i=0; i<max_func; ++i) { switch (i) { case 0: retval=Func_0(k); break; case 1: retval=Func_1(k); break; ... case n: retval=Func_n(k); break; } // use retval on some code ... }
Now, I would like to do something like ... (no laughing please!)
I know most of it is not valid syntax, but I hope the idea is clear.Code:FuncType MyFuncs[max_func]; // declare an array of "functions". MyFuncs[0]=AddressOf(Func_0); // store the function calls MyFuncs[1]=AddressOf(Func_1); ... MyFuncs[n]=AddressOf(Func_n); ... // now use them for (i=0; i<max_func; ++i) { retval=MyFuncs[0](k); // use retval ... }
Is this possible?
Thks





)
Reply With Quote