Path: utzoo!attcan!utgpu!watmath!julian!uwovax!2014_5001 From: 2014_5001@uwovax.uwo.ca Newsgroups: comp.lang.c Subject: Re: What is alloca()? [Is this unportable implementation OK?] Message-ID: <3839.251f4ecf@uwovax.uwo.ca> Date: 26 Sep 89 14:26:22 GMT References: <3823.2518c141@uwovax.uwo.ca> Lines: 40 In article <3823.2518c141@uwovax.uwo.ca>, 2014_5001@uwovax.uwo.ca writes: > I was trying to compile FLEX with TurboC 2.0. Not having a yacc, I > ran bison on parse.y. > > With a minor change in the source, I managed to get the whole thing > compiled. Unfortunately, it requests the presence of an alloca() > routine, apparently with a prototype like: > void *alloca(size_t s); > (As well as I can tell from the context and the type casting). > It does not appear to figure in parse.y, so it appears likely to me > that it is put in by my bison. What does alloca() do? > It does not appear in the TurboC 2.0 library, nor in Unix SysV > man pages. I rarely follow up on my own articles, but here goes.. I have used the following alloca() implementation for the ibm pc (highly unportable): ----- alloca.h---- static unsigned int _INtERNAL_alloca_; #define alloca(x) \ ( _INtERNAL_alloca_=_SP, _SP-=(x), (void *)_INtERNAL_alloca_ ) ----- I am wondering whether this does what alloca() should do. Have I missed something? Turbo C apparently allocates stack space for all the blocks in a function once at the top. i.e. given void f(void) { int a; { int b; } }, space for both a and b will be allocated at the top of the function, and deallocated upon return. This means that since my alloca() macro relies on the automatic var deallocation, the space will be in use until a return. -- Alexander Pruss, at one of: Department of Applied Mathematics, Astronomy, Mathematics, or Physics University of Western Ontario pruss@uwovax.uwo.ca pruss@uwovax.BITNET A5001@nve.uwo.ca