How to declare an array of function pointers without using typedef for a function pointer?

I demonstrated to a teaching colleague how to use function pointers and how he could have an array of them. I set out the following code so that it can do an indexed submission:

typedef void (*VoidFunction)(); VoidFunction functions[]  = {editProgramName, editProgramLength, editProgramCycles, editProgramNumberOfSets, editProgramEditSets, editProgramSave, editProgramCancel}; // now dispatch           functions[scroll.arrayFocusIndex](); 

And then he asked ... "How can I do this without typedef?" I found that after I tried to find different things that seemed to work, I had no idea. All the google hits I found always seemed to use typedef. Is there a way to do this inline without a typedef function pointer?

+6
source share
2 answers
 void (*functions[])() = {editProgramName, editProgramLength, editProgramCycles, editProgramNumberOfSets, editProgramEditSets, editProgramSave, editProgramCancel}; // now dispatch functions[scroll.arrayFocusIndex](); 
+4
source

This worked for me:

 void a() { } void b() { } void (*functions[2])(); int main() { functions[0] = a; functions[1] = b; return 0; } 
+3
source

All Articles