| |||||
Technical Support Support Resources
Product Information | C51: MIXING REENTRANT FUNCTIONS AND NON-REENTRANT FUNCTIONSInformation in this article applies to:
QUESTIONIs 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? ANSWERYes. 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
Last Reviewed: Wednesday, February 28, 2001 | ||||
| |||||