[comp.lang.c] alloca implementation

bright@Data-IO.COM (Walter Bright) (08/05/88)

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.