| |||||
Technical Support Support Resources
Product Information | BL51: CALL TREE USING POINTERS TO FUNCTIONSInformation in this article applies to:
QUESTIONAt the bottom of page 330 in the C51 Compiler User's Guide (01.97) it states that "when you use a function pointer, the linker cannot correctly create a call tree for your program. For this reason, you may have to correct the call tree for the data overlaying.". I have created a project that involves function pointers and I have not had to make any corrections to the call tree. Why is this? ANSWERThere are a few cases in which the C51 compiler and Linker can automatically make the proper inferrences for you and can indeed build the call tree. However, this is not always (and not typically) the case. For example, in the following example program...
#include "reg51.h"
#include "stdio.h"
static int func1 (unsigned x)
{ return (x + 1); }
static int func2 (unsigned x)
{ return (x + 2); }
int indirect_caller (int (*func) (int))
{ return ((*func) (123)); }
void main (void)
{
int junk;
SCON = 0x50;
TMOD |= 0x20;
TH1 = 221;
TR1 = 1;
TI = 1;
junk = indirect_caller (func1);
printf ("%d\n", junk);
junk = indirect_caller (func2);
printf ("%d\n", junk);
}
The call tree indicates that func1 and func2 are called from the main function when in fact they are called from the indirect_caller function. This must be corrected using the OVERLAY linker directive. MORE INFORMATION
SEE ALSO
FORUM THREADSThe following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Monday, October 16, 2006 | ||||
| |||||