I'm trying to understand how to implement a two-dimension table of function pointers (to simplify a semi-complex switch/case/if construct).
The following worked - after some wrangling - as desired.
#include <stdio.h>
void AmpEn(void) {printf("AmpEn\n");}
void MovCurColumn1(void) {printf("MovCur\n");}
void AmpLevel(void) {printf("AmpLevel\n");}
void Phase(void) {printf("Phase\n");}
typedef void (*func_ptr)(void);
int main (void) {
func_ptr table[2][2] = {{AmpEn, MovCurColumn1},{AmpLevel, Phase}};
func_ptr *p;
// runs all the fcns
for (p = &table[0][0]; p < &table[0][0] + 4; p++) {
(*p)();
}
// calls 0th fcn
p = &table[0][0];
(*p)(); p++;;
(*p)();
// calls 2nd fcn
table[0][1]();
return 0;
}
Now what I want is to pass arguments to the functions - for example, to change void Phase(void)
to
void Phase(int mode)
and call it via some similar construct to:
table[1][1](TRUE);
but I haven't figured out how to do this. Any help welcome.