on this follow program I've tried to make a function that returns a pointer to array of 4 function pointers but I don't know the way how it works and how can I call it and receive the return value also there is an array of 4 function pointers (made it to extract the difference but I Couldn't) now I'm confused of the way that I can call the functions from any 2 of these methods whether array or the Function.
#include <stdio.h>
uint32 (*(*Fun2Ptr(void))[4])(void);
uint32 Function_1(void);
uint32 Function_2(void);
uint32 Function_3(void);
uint32 Function_4(void);
uint32(*Arrayof4FP[4])(void) = {Function_1 ,Function_2 ,
Function_3 ,Function_4};
int main()
{
uint32(*(*LocalMainArrof4FP)[4])(void) = Fun2Ptr();
printf("---------------Array--------------\n");
printf("%i \n" , (*Arrayof4FP[0])()); // 1
printf("%i \n" , (*Arrayof4FP[1])()); // 2
printf("%i \n" , (*Arrayof4FP[2])()); // 3
printf("%i \n" , (*Arrayof4FP[3])()); // 4
printf("-----------Using Function-------------\n");
printf("%i \n" ,(*LocalMainArrof4FP)[0]() ); // 1
printf("%i \n" ,(*LocalMainArrof4FP)[1]() ); // 2
printf("%i \n" ,(*LocalMainArrof4FP)[2]() ); // 3
printf("%i \n" ,(*LocalMainArrof4FP)[3]() ); // 4
return 0;
}
uint32 Function_1(void)
{
return 1;
}
uint32 Function_2(void)
{
return 2;
}
uint32 Function_3(void)
{
return 3;
}
uint32 Function_4(void)
{
return 4;
}
uint32 (*(*Fun2Ptr(void))[4])(void)
{
uint32 (*(*LocalPtrs)[4])(void) = &Arrayof4FP;
return LocalPtrs;
}
typedef uint32 (*funcptr)(void);. Then you can use it as any other type, likefuncptr* Fun2Ptr(void);orfunptr Arrayof4FP[] = { ... };funcptr (*localptrs)[4] = &Arrayof4FP;, you can just dofuncptr *localptrs = Arrayof4FP; /* Same as &Arrayof4FP[0] */Then you can just uselocalptrs[i]like any other array.typedefor include foruint32.