Article View: comp.os.msdos.programmer
Article #1935Re: alloca() for TurboC
From: Alex Pruss
Date: Mon, 27 Aug 1990 17:22
Date: Mon, 27 Aug 1990 17:22
34 lines
2193 bytes
2193 bytes
In article <1990Aug22.032243.18214@usenet.ins.cwru.edu> trier@po.CWRU.Edu writes:
>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))
This looks surprisingly like the original of my alloca(). Unfortunately it
doesn't work. (Not at all!--my version didn't either--it took many hours
of painful debugging to find what was wrong.) You see it returns SS:SP.
However, next time a function call, push, or interrupt comes along, a word
gets stored at SS:SP which is part of the allocated area. Thus a minimal
fix is to change it to:
#define alloca(A) ((_SP -= ((A)+1) & 0xFFFE), (void far *)(((unsigned long)_SS << 16) | _SP+2))
Unfortunately this fails in the case that the function has stored DS/SI/DI
on the stack. Furthermore one must beware that the calling function may not
have a proper stack frame.
>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.)
It was less elegant in the forcing of A to be even, and it too didn't work.
It included also a { char dummy; dummy=dummy; } type of thing to force a
stack frame.
Anyways, the latest WORKING (I hope... I tested it...) version I've just posted
to alt.sources. (The whole thing with docs and uuencoded object files is
13Kb, so I didn't want to post it here).
pruss@uwo.ca // internet
pruss@uwovax // bitnet
pruss@ria // uucp
//\\ The SCHSPH Guy //\\
Technical Details
Message-ID:
<917@ria.ccs.uwo.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!ria!prussReferences:
<2745@onion.reading.ac.uk> <3860@bingvaxu.cc.binghamton.edu> <1990Aug22.032243.18214@usenet.ins.cwru.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!ria!pruss From: pruss@ria.ccs.uwo.ca (Alex Pruss) Newsgroups: comp.os.msdos.programmer,alt.msdos.programmer,comp.lang.c Subject: Re: alloca() for TurboC Keywords: alloca, DOS, TurboC, assembly Message-ID: <917@ria.ccs.uwo.ca> Date: 27 Aug 90 17:22:28 GMT References: <2745@onion.reading.ac.uk> <3860@bingvaxu.cc.binghamton.edu> <1990Aug22.032243.18214@usenet.ins.cwru.edu> Followup-To: comp.os.msdos.programmer Organization: Applied Mathematics, University of Western Ontario, London Lines: 34