ARM Technical Support Knowledge Articles

CALL TREE USING POINTERS TO FUNCTIONS

Applies to: BL51 Code-banking Linker/Locator

Answer


Information in this article applies to:


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
", junk);

junk = indirect_caller (func2);
printf ("%d
", 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

Article last edited on: 2006-10-16 10:46:06

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential