|
|||||||||||
|
Technical Support On-Line Manuals BL51 User's Guide |
BL51 User's GuideIn a Local VariableWhen a function address is assigned to a local variable (a function pointer), a reference is created in the function where the assignment occurs. If that function also uses the pointer to invoke the function assigned to it, the call tree generated by the linker is accurate. If the function address assigned to the pointer is used in another function (either by returning it or by passing it as an argument),the call tree generated by the linker is inaccurate. 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 caller (int (*fp2) (int, int, int))
{
int retval;
retval = direct_func(4,5,6);
retval += (*fp2) (1,2,3);
return (retval);
}
void main (void)
{
int value;
int (*fp) (int, int, int) = indirect_func;
value = caller(fp);
while (1);
}
The correct Call Tree is illustrated by the following flow chart.
However, since indirect_func is referenced in the main function and not in the caller function, 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?_INDIRECT_FUNC?MAIN +--> ?PR?_CALLER?MAIN _INDIRECT_FUNC/MAIN ----- ----- 000AH 000BH _CALLER/MAIN ----- ----- 000AH 000EH +--> ?PR?_DIRECT_FUNC?MAIN _DIRECT_FUNC/MAIN ----- ----- 000FH 0010H The linker call tree must be adjusted by removing the reference from main to indirect_func and adding a reference from caller to indirect_func using the following overlay command: ... OVERLAY(main ~ indirect_func, caller ! indirect_func) ... After adjusting the call tree, the Overlay Map appears as follows: 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 000EH +--> ?PR?_DIRECT_FUNC?MAIN +--> ?PR?_INDIRECT_FUNC?MAIN _DIRECT_FUNC/MAIN ----- ----- 000FH 0010H _INDIRECT_FUNC/MAIN ----- ----- 000FH 0010H | ||||||||||
|
|||||||||||