What is alloca()? [Is this unportable implementation OK?]

Dave Rifkind dave at dsi.COM
Fri Oct 6 13:10:54 AEST 1989


In article <417 at bgalli.eds.com> bga at 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.



More information about the Comp.lang.c mailing list