scope of malloc

Andrew Koenig ark at alice.att.com
Sun Nov 18 04:02:44 AEST 1990


In article <4251 at goanna.cs.rmit.oz.au> ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
> In article <3739 at skye.ed.ac.uk>, richard at aiai.ed.ac.uk (Richard Tobin) writes:
> > Are there *any* widely-used processors
> > that can't implement alloca() reasonably efficiently even with
> > compiler support?

> Any processor that can't implement alloca() as a built-in operation is
> going to have a hard time with PL/I, Fortran 90, and Ada, all of which
> allow the declaration of local variables whose size is not known until
> the declaration is elaborated.  The fact that gcc supports alloca() as
> well as "auto int foo[some_expr()]" is not a coincidence.

Quite true -- most C compilers will have a hard time compiling PL/I or Ada!

Seriously, though, if one decides to make it impossible to support
alloca(), as the definition of ANSI C allows, it is sometimes possible
to produce significantly faster object code as a result.

For example, barring alloca() means that the compiler can always know
the size of the stack frame.  That, in turn, means that it is possible
to maintain the stack using only a single pointer.  That implies that
a function call need update only one stack register and not two.

-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list