alloca implementation
Walter Bright
bright at Data-IO.COM
Fri Aug 5 05:35:21 AEST 1988
In order to successfully implement alloca():
1. Automatic variables must be implemented using a frame pointer
register rather than offsets from the stack register.
2. Functions containing alloca() must have a stack frame (this is
a problem because many compilers generate a stack frame only
if there are non-register automatics).
3. Evaluation of arguments becomes a problem if the code generator
uses the stack, as in:
func(1,2,3,4,5,p=alloca(10),6,7,8,9,10);
(On some implementations of alloca() that I've seen, the above
will cause a program crash.)
4. If the code generator uses the stack to store temporary results
when it runs out of registers, alloca() can cause it to lose
it's place.
Of course, alloca() could be implemented by having the compiler recognize
it and then modify the behavior of the code generator. This seems like a
lot of implementation effort for a minor return, however.
More information about the Comp.lang.c
mailing list