I want to call a number of functions with function pointers. I have studied a number of posts and App. notes, including APNT 129 and I am still getting a linker error. On page 7 of APNT 129 is says:- The following is a function pointer table definition that C51 and BL51 can handle automatically: code long (code *fp_tab []) (void) = { func1, func2, func3 }; Note that the only difference is storing the table in CODE space. and later:- As long as the function pointer table is located in a separate source file, C51 and BL51 make all the correct links in the call tree for you. I assume the .h file is OK for "a separate source file"
Here is my code:- in the myprog.h file:-
extern uchar set_day(uchar xpos, uchar ypos, uchar action); extern uchar set_hours(uchar xpos, uchar ypos, uchar action); extern uchar set_mins(uchar xpos, uchar ypos, uchar action); // Function pointer table code uchar(code *set_table[])(uchar, uchar, uchar) = {set_day, set_hours, set_mins};
in the myprog.c file:-
#include "myprog.h" /* Declarations*/ ........ ........ main(){ ..... ..... // function called with:- (*set_table[0])(an_xval, a_yval, an_action); ..... ..... ..... } // Functions:- (after main() in myprog.c) uchar set_day(uchar xpos, uchar ypos, uchar action){ ... ... } set_hours(uchar xpos, uchar ypos, uchar action){ ... ... } set_mins(uchar xpos, uchar ypos, uchar action){ ... ... }
When I link this, I get three L13 warnings. The M51 file reports:-
... ... PROGRAM RECURSIONS REMOVED FROM CALL TREE ========================================= +--> ?CO?RGE_MAIN_04 <--+ ?PR?_SET_DAY?RGE_MAIN_04 +--> ?CO?RGE_MAIN_04 <--+ ?PR?_SET_HOURS?RGE_MAIN_04 +--> ?CO?RGE_MAIN_04 <--+ ?PR?_SET_MINS?RGE_MAIN_04 ... ... *** WARNING L13: RECURSIVE CALL TO SEGMENT SEGMENT: ?CO?RGE_MAIN_04 CALLER: ?PR?_SET_DAY?RGE_MAIN_04 *** WARNING L13: RECURSIVE CALL TO SEGMENT SEGMENT: ?CO?RGE_MAIN_04 CALLER: ?PR?_SET_HOURS?RGE_MAIN_04 *** WARNING L13: RECURSIVE CALL TO SEGMENT SEGMENT: ?CO?RGE_MAIN_04 CALLER: ?PR?_SET_MINS?RGE_MAIN_04
I would rather not have these warnings but is it safe to ignore them, bearing in mind the code seems to work when I download it. (I have only called the first pointer so far.)