Keil Logo

BL51: Call Tree Using Pointers to Functions


Information in this article applies to:

  • C51 Version 5.50

QUESTION

At 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?

ANSWER

There 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

  • Refer to Application Note 129: Function Pointers in C51 for a complete discussion of all the ramifications of using function pointers with the C51 compiler.
  • Refer to OVERLAY in the BL51 User's Guide.
  • Refer to Function Pointers in the BL51 User's Guide.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.