alloca() for TurboC

Stephen C. Trier trier at cwlim.CWRU.EDU
Wed Aug 22 13:22:43 AEST 1990


Here's a version of alloca I use.  It's my clone of a version from some
piece of PD software I saw a year or two ago.

        #define alloca(A) ((_SP -= ((A)+1) & 0xFFFE), (void far *)(((unsigned long)_SS << 16) | _SP))

The idea is to subtract the size A from the stack pointer, making sure
it's word-aligned.  (This is the (_SP -= ((A)+1) & 0xFFFE) part.)  Then,
since alloca returns a pointer to the allocated space, the macro must
kludge together a far pointer from the stack segment and stack pointer.

I should add the disclaimer that I'm not entirely sure that this works.
It's my own version of someone else's, but I changed it a bit.  (I don't
remember what the original looked like.)

Hope this helps!

-- 
Stephen Trier                              Case Western Reserve University
Home: sct at seldon.clv.oh.us                 Information Network Services
Work: trier at cwlim.ins.cwru.edu
   I may work for the University, but that doesn't mean I speak for them.



More information about the Comp.lang.c mailing list