5.8.1.3 Reentrant And Nonreentrant Specifiers

The __reentrant and __nonreentrant function specifiers indicate the function model (stack) that should be used for that function’s stack-based variables (auto and parameters), as shown in the Table 5-11 table. The aliases __software and __compiled, respectively, can be used if you prefer. You would only use these specifiers if the default allocation is unacceptable.

Table 5-11. Stack Related Function Specifiers
Specifier Allocation for Stack-based variables
__compiled, __nonreentrant Always use the compiled stack; functions are nonreentrant
__software, __reentrant Use the software stack, if available; functions are reentrant

The following shows an example of a function that will always be encoded as reentrant.

__reentrant int setWriteMode(int mode)
{
    accessMode = (mode!=0);
    reutrn mode;
}

These specifiers override any setting indicated using the -mstack option (see 4.6.1.23 Stack Option). If neither function specifier is used with a function and the -mstack option is not specified (or specified as hybrid), then the compiler will choose the stack to be used by that function for its stack-based variables.

The __reentrant specifier only has an effect if the target device supports a software stack. In addition, not all functions allow reentrancy. Interrupt functions must always use the compiled stack, but functions they call may use the software stack. Functions encoded for Baseline and Mid-range devices always use the nonreentrant model and the compiled stack.

Repeated use of the __software (__reentrant) specifier will increase substantially the size of the software stack leading to possible overflow. The size of the software stack is not accurately known at compile time, so the compiler cannot issue a warning if it is likely to overwrite memory used for some other purpose.

See 5.7.2 Data Stacks for device specific information relating to the data stacks available on each device.