Hi What is the point of using pointers to functions in C ? Why not call directly a function ?
Thanks Elico
consider a situation where you have an uart or a keypad from where the user is going to give input commands at runtime. depending upon the commands, the functions will be executed.
under such a case you will have a very big if-else (alternatively switch-case) statement.
if(input_cmd == 0x01) function1(); else if(input_cmd == 0x02) function2(); else if(input_cmd == 0x03) function3(); ... else if(input_cmd == 0xFF) function255(); // The list will be very long, clumsy, unorganized, poor readability
on contrary, consider an array of function
CMDS_Functn FunctionArray1[256] = { /*00-07*/ (*NotDef),(*funtion1),(*function2),(*function3), ... /*F7-FF*/ (*function254), (*function255)}; //functions can be called as Cur_Func = FunctionArray1[input_cmd].Cur_FunctnPtr; //Load current Function Pointer (*Cur_Func)();