Sergio Masci said:
You don't need a new storage class to do this. The compiler just needs to be
intelligent enough to analyse the code, determin that a function is not
reenterent and allocate locals accordingly.
The compiler doesn't really have enough information to deternine that.
Suppose you have a source file like this:
extern void func1 (int c);
static void func2 (int b)
{
int foo = b % 6;
// do some stuff with foo
func1 (foo - 7);
// do some other stuff with foo
}
void func3 (int a)
{
func2 (a + 3);
}
Even though func2() is declared static, and even though there is only a
single place that calls func2(), the compiler cannot determine whether it
can be called recursively because it has no way to know whether the
external func1() might call func3(). The best the compiler can do in
this case is decide that func2 *might* be called recursively, and thus
take the proper actions to guarantee that local variable foo meets the
defined semantics for the automatic storage class. Typically this would
involve storing foo in a stack frame, or pushing it prior to the call
to func1() and restoring it afterward, though other mechanisms not
involving a stack could also be used.
If you restrict the program to a single compilation, or get the linker
involved, you can statically determine which functions are not recursively
called provided that you don't use function pointers.
The point of my suggestion is that the programmer generally has some idea
as to whether the function can be called recursively (though he or she may
be mistaken), and it is much easier for the programmer to provide a hint
to the compiler than for the compiler to figure it out.