Article View: comp.os.msdos.programmer
Article #1860Re: alloca() for TurboC
From: R. Kym Horsell
Date: Sat, 18 Aug 1990 13:51
Date: Sat, 18 Aug 1990 13:51
37 lines
2083 bytes
2083 bytes
In article <2745@onion.reading.ac.uk> ssuhook@susssys1.cs.reading.ac.uk writes:
\\\
>In summary, I am mainly interested in finding out how to get an alloca() for
>the PC for Turbo C, and also what it is that alloca() actually does.
\\\
Alloca does something *like*
char *alloca(n) {
n = /* round up to words */;
((char*)SP) += n; /* bump up the stack ptr */
return (char*)SP-n; /* return address of stuff on stack */
}
I.e. it just bumps up the stack by n bytes (usually word alignining
the result) and returns the address of the new stack section.
Since the SP is restore by C exit stuff from a `frame ptr register'
(typically, anyway) this memory is deallocated at the end of the function.
Note I've assumed the stack grows up (not a normal thing these days).
Also we can't *actually* write alloca() as above even when you can
refer to the SP directly since its exit will deallocate the
space just allocated -- you should think of alloca() as written
above as a macro.
To solve your problem with proting Bison -- why not use
(a) malloc/alloc and just forget deallocating it, or
(b) malloc/alloc and use an explicit free at the end of
the function its used it (might as well catch *all*
returns from the function while you're about it).
Ive written a fairly complete Yacc/Lex for AT's and didn't
both about memory leakage. After a PDP-11 there was more memory
than I new what to do with (ahhh...many years ago now).
Hope this's been some help,
-Kym Horsell
Technical Details
Message-ID:
<3860@bingvaxu.cc.binghamton.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!rpi!leah!bingvaxu!vu0310References:
<2745@onion.reading.ac.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!rpi!leah!bingvaxu!vu0310 From: vu0310@bingvaxu.cc.binghamton.edu (R. Kym Horsell) Newsgroups: comp.os.msdos.programmer,alt.msdos.programmer,comp.lang.c Subject: Re: alloca() for TurboC Keywords: alloca, DOS, TurboC, assembly Message-ID: <3860@bingvaxu.cc.binghamton.edu> Date: 18 Aug 90 13:51:21 GMT References: <2745@onion.reading.ac.uk> Reply-To: vu0310@bingvaxu.cc.binghamton.edu.cc.binghamton.edu (R. Kym Horsell) Organization: SUNY Binghamton, NY Lines: 37