Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!dsi!dave From: dave@dsi.COM (Dave Rifkind) Newsgroups: comp.lang.c Subject: Re: What is alloca()? [Is this unportable implementation OK?] Message-ID: <257@dsi.COM> Date: 6 Oct 89 03:10:54 GMT References: <3823.2518c141@uwovax.uwo.ca> <3839.251f4ecf@uwovax.uwo.ca> <417@bgalli.eds.com> Reply-To: dave@dsi.UUCP (Dave Rifkind) Organization: KFW Corporation, Newbury Park, CA Lines: 18 In article <417@bgalli.eds.com> bga@bgalli.eds.com (Billy G. Allie) writes: : I am including the source for :the macro that I wrote when I ported BISON to the MS-DOS operating system :and the Turbo-C compiler. It will work correctly for any data model. ... :#if !defined(alloca) :#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__) :#define alloca(i) (_SP-=((i+1)&0xFFFE),(void *)(((unsigned long)_SS<<16)|_SP)) :#else :#define alloca(i) (_SP-=((i+1)&0xFFFE),(void *)_SP) :#endif :#endif Just be careful not to use this in a function with very few local variables. If Turbo C does not have to adjust the stack pointer (to allocate locals) in the function prologue, it will not generate a "mov sp, bp" in the return sequence. This would make returning from such a function interesting, but not useful.