Automatic (local) variables and parameters to functions can either
be placed on the stack or in data-space. The default action of the
compiler is to place these variables in the internal RAM (for small
model) or external RAM (for large model). This in fact makes them
static so by default functions are non-reentrant.
They can be placed on the stack either by using the
--stack-auto option or by using the
reentrant keyword in the function declaration,
e.g.:
unsigned char foo(char i) reentrantSince stack space on 8051 is limited, the reentrant keyword or the --stack-auto option should be used sparingly. Note that the reentrant keyword just means that the parameters & local variables will be allocated to the stack, it does not mean that the function is register bank independent.
{
...
}
unsigned char foo()In the above example the variable i will be allocated in the external ram, bvar in bit addressable space and j in internal ram. When compiled with --stack-auto or when a function is declared as reentrant this should only be done for static variables.
{
xdata unsigned char i;
bit bvar;
data at 0x31 unsigned char j;
...
}
Parameters however are not allowed any storage class, (storage classes for parameters will be ignored), their allocation is governed by the memory model in use, and the reentrancy options.