Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!vsi1!wyse!mips!sah@gumby From: sah@gumby (Steve Hanson) Newsgroups: comp.sys.mips Subject: Re: alloca(3C) Message-ID: <26677@gumby.mips.COM> Date: 1 Sep 89 15:11:28 GMT References: <11601@polya.Stanford.EDU> Sender: sah@mips.COM Reply-To: sah@gumby (Steve Hanson) Organization: MIPS Computer Systems, Sunnyvale CA Lines: 64 In-reply-to: ramani@modesty.Stanford.EDU (Ramani Pichumani) In article <11601@polya.Stanford.EDU>, ramani@modesty (Ramani Pichumani) writes: > >Does anyone have a real working version of alloca(3C) for the MIPS >compiler? I'm using a Silicon Graphics 4D R2000 box which doesn't >come with alloca() in its library. Doug Gwen's semi-portable version >won't do for my application since I truly need to extend the stack. >I'm aware that the use of alloca() is discouraged because it is >compiler and machine dependent. Yet all the Berkeley UNIX machines >I've used seem to have it. And besides, allocating memory locally >seems like a very convienent way of cleaning up garbage that is local >to a procedure. Furthermore, dynamically allocated local memory can >ease fragmentation problems with the heap. > >I've been told by one source that alloca() can't be truly implemented >on a MIPS compiler because of the way it handles it's stacks. I hope >this isn't the case. > >Ramani Pichumani Tel: (415) 723-2902 or 723-2437 >Department of Computer Science Fax: (415) 725-7411 >Margaret Jacks Hall, Room 308 email: ramani@patience.stanford.edu >Stanford, CA 94305 USA uunet!patience.stanford.edu!ramani alloca has been implemented as a built-in operator in the upcoming 2.10 compiler when alloca.h is included, otherwise you will get the portable version. The following is taken from alloca.h: ------------------------------------------------------------------------------- /* --------------------------------------------------- */ /* | Copyright (c) 1986 MIPS Computer Systems, Inc. | */ /* | All Rights Reserved. | */ /* --------------------------------------------------- */ /* $Header: alloca.h,v 1.1 89/07/19 17:29:15 lai Exp $ */ #ifndef __ALLOCA_H #define __ALLOCA_H /* ** Synopsis ** #include ** void *alloca(integral_types); ** ** Description ** This header is to be included if the built-in version ** of alloca is desired. The built in version is more ** efficient than the libc version, but it is less ** flexible. The built-in version is implemented as an ** operator and can only be applied to integral_types. ** integral_types are comprised of type char, the signed ** and unsigned integer types, and the enumerated types. ** See also alloca(3). */ #define alloca __builtin_alloca #endif ---------------------------------------------------------------------------- Less flexible means it can't be assigned or its address can't be taken. --