Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!shamash!nic.MR.NET!thor.acc.stolaf.edu!mike From: mike@thor.acc.stolaf.edu (Mike Haertel) Newsgroups: comp.lang.c Subject: Re: What is alloca()? [Generated by bison from flex] Message-ID: <6361@thor.acc.stolaf.edu> Date: 25 Sep 89 05:43:03 GMT References: <3823.2518c141@uwovax.uwo.ca> <1989Sep24.050214.13898@utzoo.uucp> Reply-To: mike@stolaf.edu (Mike Haertel) Organization: Free Software Foundation Lines: 37 In article <1989Sep24.050214.13898@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >In article <3823.2518c141@uwovax.uwo.ca> 2014_5001@uwovax.uwo.ca writes: >>... What does alloca() do? >>It does not appear in the TurboC 2.0 library, nor in Unix SysV >>man pages. > >It's a nonstandard botch (originating in some poorly-designed ancient Unix >systems) that some of the Gnoids are really fond of. The theory is that >it's malloc() except that the storage automatically goes away when you leave >the function it was called in. This is more than a little difficult to >implement on some machines... I'm glad you said "SOME OF the Gnoids" (emphasis mine), Henry. Not all of us are particularly fond of alloca(). I think alloca() originated in one of the early VAX BSD's. My guess would be that it was invented for use implementing Franz Lisp, and somehow wormed its way into the standard library during a lapse of judgement on someone's part. The practical problem with alloca() is that it cannot be implemented on machines without a frame pointer (except by compiler hack) and therefore is not available in all environments. There are philosophical objections too, but I won't go into them. Unfortunately, alloca() is sometimes necessary in programs that call longjmp(). (longjmp(), like alloca(), is evil. Even though it is in the C standard.) But two wrongs do not make a right . . . Doug Gwyn (gwyn@smoke.brl.mil) has a semi-portable fake alloca() written in C that people without alloca() may find useful when installing GNU software on their machines. -- Mike Haertel``There's nothing remarkable about it. All one has to do is hit the right keys at the right time and the instrument plays itself.'' -- J. S. Bach