alloca() portability

Doug Gwyn gwyn at smoke.brl.mil
Wed Nov 7 22:13:00 AEST 1990


In article <499 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
-There is more to it than the target machine.  Some compilers get a
-performance win by omitting frame pointers and leveling the stack only
-when actually needed.  The compiler keeps track of the top of the
-stack, and parameter and local variable references are relative to the
-current TOS rather than to the FP.  Upon return from a function, the
-stack is not necessarily popped -- it gets leveled only when different
-flow paths converge.  With such a stack management strategy, alloca
-cannot be implemented as a library routine -- it would have to be built
-into the compiler.

But that doesn't adversely affect my alloca() strategy.

It is worth repeating over and over:  DON'T WRITE CODE THAT USES alloca()!
I provided my alloca() implementation solely in support of existing code
that needs to be ported and for which fixing its use of alloca() would be
too painful.



More information about the Comp.lang.c mailing list