ARM Technical Support Knowledge Articles

MIXING REENTRANT FUNCTIONS AND NON-REENTRANT FUNCTIONS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

Is it possible to mix reentrant and non-reentrant functions in the same program? Can a non-reentrant function call a reentrant function which then calls another non-reentrant function?

ANSWER

Yes. The compiler and linker keep track of all memory used by the non-reentrant functions and create a call tree that is correct. The overlaid memory will be maintained correctly.

In the following example:

#pragma noregparms

unsigned int f1 (unsigned char arg1, unsigned char arg2)
{
return ((unsigned) arg1 << 8) | arg2;
}


unsigned int r1 (unsigned char arg1, unsigned char arg2) reentrant
{
return f1(arg1, arg2);
}


unsigned int f2 (unsigned char arg1, unsigned char arg2)
{
return r1 (arg1, arg2);
}

void main (void)
{
unsigned int j;

j = f2 (0x12, 0x34);

while (1);
}

The main function calls f2, which calls r1 (which is reentrant), which calls f1 (which is not reentrant). The linker builds the following call tree for this example:

SEGMENT                          DATA_GROUP
  +--> CALLED SEGMENT          START    LENGTH
----------------------------------------------
?C_C51STARTUP                  -----    -----
  +--> ?PR?MAIN?MAIN

?PR?MAIN?MAIN                  0008H    0002H
  +--> ?PR?F2?MAIN

?PR?F2?MAIN                    000AH    0002H
  +--> ?PR?_?R1?MAIN

?PR?_?R1?MAIN                  -----    -----
  +--> ?PR?F1?MAIN

?PR?F1?MAIN                    000CH    0002H

From this call tree, you can see that the memory used by the main function (?PR?MAIN?MAIN) at 0008h is exclusive of the memory used by the f2 function (?PR?F2?MAIN) at 000Ah and the f1 function (?PR?F1?MAIN) at 000Ch.

SEE ALSO

Article last edited on: 2001-02-28 00:00:00

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