| ||||||||
Technical Support On-Line Manuals BL51 User's Guide | In a ROM VariableWhen a function pointer is assigned to a global variable that is stored in ROM (CODE), the call tree generated by the linker may be completely accurate. For example, given the following example program:
int direct_func (int a, int b, int c)
{
volatile int total = a+b+c;
return (total);
}
int indirect_func (int a, int b, int c)
{
volatile int total = a+b+c;
return (total);
}
int (* code fp) (int, int, int) = indirect_func;
int caller (void)
{
int retval;
retval = direct_func(4,5,6);
retval += (*fp) (1,2,3);
return (retval);
}
void main (void)
{
int value;
value = caller();
while (1);
}
The correct Call Tree is illustrated by the following flow chart.
However, indirect_func is referenced by the code segment of the main source file (?co?main) that contains the function pointer fp. It is not referenced in the caller function. However, the caller function does reference the fp variable. Therefore, the linker generates the following Call Tree and Overlay Map.
FUNCTION/MODULE BIT_GROUP DATA_GROUP --> CALLED FUNCTION/MODULE START STOP START STOP ============================================================= ?C_C51STARTUP ----- ----- ----- ----- +--> ?PR?MAIN?MAIN MAIN/MAIN ----- ----- 0008H 0009H +--> ?PR?CALLER?MAIN CALLER/MAIN ----- ----- 000AH 000BH +--> ?PR?_DIRECT_FUNC?MAIN +--> ?CO?MAIN _DIRECT_FUNC/MAIN ----- ----- 000CH 000DH ?CO?MAIN ----- ----- ----- ----- +--> ?PR?_INDIRECT_FUNC?MAIN _INDIRECT_FUNC/MAIN ----- ----- 000CH 000DH The ?CO?MAIN segment contains all code variables declared in the MAIN.C file. If this consists of only function pointers, all of which are accessed by a C function, then no changes to the call tree are required. Refer to the following rules regarding global function pointers stored in CODE to determine if adjustments to the call tree are required.
Note
| |||||||
| ||||||||