We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear all, Who can help me the following question. I had wrote three routine,such as: void p1(void) { printf("1!\n"); } void p2(void) { printf("2!\n"); } void p3(void) { printf("3!\n"); } than I new a pointer and a func arrary for these func, void (code* pfun1)(void); //the pointer void (code* cFunc[])(void) = //the array { p1, p2, p3 }; then call the routine with the pointer in main routine, main() { while(1) { unsigned char i; for(i = 0 ; i < 3 ; i++) (*(cFunc+i))(); } } but the result is only execute the p1 routine,Then I think the i should be change to another type same as cFunc,So I had change the i data type as --> void (code*)(void) i; but the result is still error,who can told me how can let the routine execute corretly? Thanks a lot.
Because of the way the 8051 works, function pointers are very hard to get working correctly without manually helping the compiler to use them. In particular, you'll have to assist the call graph analysis with finding potential calls through function pointers. I guess your second code version worked because the call graph analysis by the compiler did recognize cFunc[i] as a call through one of the function pointers in cFunc[], but not the obfuscated version of writing the same thing, (*(cFunc + i)). Make sure you consult the Manual for pecularities with function pointers, too.
There is an important App Note that you need to read, and several knowledgebase articles - use the 'Search'