Article View: comp.lang.c.moderated
Article #2623Re: Legal alloca?
From: news
Date: Fri, 19 Apr 1996 14:29
Date: Fri, 19 Apr 1996 14:29
27 lines
1876 bytes
1876 bytes
In article <4l33l8$7of@solutions.solon.com> mfg@ee.edinburgh.ac.uk (Michael F Gordon) writes: >Another place where I've found alloca() very useful is to allocate >memory in a recursive descent parser for a simple calculator. >Instead of cluttering the code with error checks at every step and >having to free memory and pass error values back up the calling >chain, I just longjmp'd back to the top level parse() function >whenever one of the low level routines found an error. > >So, just how non-portable and horrible is this? > Different implementation have varing "flavours" of alloca 1) It may not exist. It is after all NOT required by the C standard. You clearly are not portable to these implementations. 2) It exists and works by playing games with the stack frame size. Your technique will not work on implementations where there are tight limits on frame size or total stack space. Fixing a maximum total stack at compile/link time is not uncommon. And being able to extend the function framesize dynamically usually requires the calling sequence to sacrifice a register. 3) It exists, but works by calling malloc(), and arranging a hidden free() on return. Your technique will only work on those implementations where longjmp() also looks after these hidden free() calls. How portable do you want to be? What range of machines do you want to support?
Technical Details
Message-ID:
<4l880s$75k@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4koe4u$8sl@solutions.solon.com> <4kr7b2$kcb@solutions.solon.com> <4l33l8$7of@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: news@Thinkage.On.CA Newsgroups: comp.lang.c.moderated Subject: Re: Legal alloca? Date: 19 Apr 1996 09:29:48 -0500 Organization: Thinkage Ltd. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4l880s$75k@solutions.solon.com> References: <4koe4u$8sl@solutions.solon.com> <4kr7b2$kcb@solutions.solon.com> <4l33l8$7of@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com