Article View: comp.lang.c.moderated
Article #2237Re: Bad Style Contest - We Have a Winner!
From: Stan Ryckman
Date: Mon, 11 Mar 1996 01:29
Date: Mon, 11 Mar 1996 01:29
52 lines
2839 bytes
2839 bytes
In article <4hv05f$j9i@solutions.solon.com>, Konrad Schwarz <schwarz@a2.complang.tuwien.ac.at> wrote: :In article <4hqed0$1lc@solutions.solon.com>, kanze@gabi-soft.fr (J. Kanze) writes: :|> [Concerning alloca...] :I: As far as I know, implementing alloca via the stack is trivial on :I: any general-purpose CPU, but I am interested in hearing of counter examples. :|> :|> So what do you do on machines that don't have a stack? : :General-purpose CPU's have stacks, at least in my book. How do you :implement C on machines that don't have a stack? How about calling malloc() at function entry, and free() at function exit? That should work. (I mean that the generated code does this, not that the programmer does this; it's invisible to him/her.) setjmp/longjmp becomes tricky to implement to avoid memory leaks, but is possible. (I don't know if my previous post re alloca() made it out or not; it didn't show here. Our newsfeed(s) is/are crummy; some stuff gets here right away, some takes nearly a week, and some never seems to show up at all. Your article and its great-grandparent are here, but not the two in between. This is not a function of which group is involved. Sorry.) There are several problems with alloca(). I couldn't think of any when I previously wrote. Here are three: 1. Think of how it would be implemented such that it would work correctly when assigned to a function pointer. For example, call some other function with malloc sometimes and alloca sometimes as an argument. 2. Try this: char *base, *interesting_stuff; int f1(), f2(); interesting_stuff = f1() + (base=alloca(SIZE)) + f2(); How would you implement alloca() to handle this? 3. Since the standard chose (probably for good reasons :) to omit alloca, porting code that uses it can be a real b**ch. I once had to deal with some code that had called alloca() IN A LOOP (otherwise, I could have just replaced: alloca with malloc, saving ptr return with goto EXIT and added: EXIT: free(ptr); return; which is easy (in the absence of setjmp/longjmp, anyway).) Cheers, Stan. -- Stan Ryckman (stanr@tiac.net) (new e-mail address)
Technical Details
Message-ID:
<4hvvmm$oqr@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4fjmdt$og4@solutions.solon.com> <4hgc5l$99s@solutions.solon.com> <4hqed0$1lc@solutions.solon.com> <4hv05f$j9i@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: stanr@tiac.net (Stan Ryckman) Newsgroups: comp.lang.c.moderated Subject: Re: Bad Style Contest - We Have a Winner! Date: 10 Mar 1996 19:29:58 -0600 Organization: Amber & Sneakers Fan Club Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4hvvmm$oqr@solutions.solon.com> References: <4fjmdt$og4@solutions.solon.com> <4hgc5l$99s@solutions.solon.com> <4hqed0$1lc@solutions.solon.com> <4hv05f$j9i@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com