Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!mailrus!husc6!spdcc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: alloca Message-ID: <5727@haddock.ISC.COM> Date: 2 Aug 88 20:39:14 GMT References: <3950010@eecs.nwu.edu> <62170@sun.uucp> <62363@sun.uucp> <8293@smoke.ARPA> <19895@cornell.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 29 In <19895@cornell.UUCP> aitken@svax.cs.cornell.edu (William Aitken) writes: >In <8293@smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >>The C vendors aren't evil (?) either; requiring support for alloca() >>does impose an undue burden on implementations on some architectures. >> >Could someone give a concrete example of an architecture on which alloca is >difficult to implement, and explain what it is that makes automatic >arrays possible, but alloca difficult? The AIX compiler on the IBM RT/PC. A single register is used for the stack pointer, frame pointer, and arg pointer; the compiler generates appropriate offsets based on its knowledge of the frame size%. If (as in the usual implementation of alloca) you tried to change the frame pointer on the fly, all hell would break lose. My conclusion (I analyzed this problem when porting GNU Emacs&, which makes heavy use of alloca) was that a proper alloca would have to be written as a compiler builtin$. In this case the cost would be one extra register, in only those functions that happen to use alloca. This doesn't seem like an undue burden. I agree with the FSF on this one. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ________ % The frame size depends on the number of registers used by the current routine, the number of automatic variables, and the number of arguments passed to subroutines, but is independent of the number of arguments passed to the routine itself. Thus variadic functions work too. & Sorry, I'm no longer providing the Emacs diffs. They're outdated. $ I could almost have done it by postprocessing the .s file, but I couldn't find a way to get the compiler to not use all the registers.