I am currently experimenting with function pointers as part of a larger project. Drawing from both online sources and textbooks.
The problem however is that after storing the values as an array, when i call them the functions either fail to be called, or if i attempt to print the return value from the function i end up simply printing the memory address(no matter how i alter the pointing). Probably missing a fairly un-subtle error but... i can't see it.
compiler:
GCC with -ansi flag
implementation 1:
void caller(int name){
int (*f[NUMBEROFFUNC])(void)= { &aR1, &aR2, &aR3};
printf("%d\n", (*f[name])); /*statement to print return value*/
}
implementation 2:
typedef int (*funcptr)(void);
void caller(int name){
funcptr *funcarr[NUMBEROFFUNC] = {NULL}; /*position in array is pointer to data*/
funcarr[0]= &aR1;
funcarr[1]= &aR2;
funcarr[2]= &aR3;
printf("%d\n", (*funcarr[name])); /*statement to print return value*/
}
Any assistance is greatly appreciated.