Re: What's wrong with alloca() ?

wws@renaissance.cray.com (Walter Spector)
Mon, 30 Dec 91 13:14:39 PST

          From comp.compilers

Related articles
[2 earlier articles]
Re: What's wrong with alloca() ? pardo@cs.washington.edu (1991-12-21)
Re: What's wrong with alloca() ? preston@dawn.cs.rice.edu (1991-12-22)
Re: What's wrong with alloca() ? wjw@eb.ele.tue.nl (1991-12-23)
Re: What's wrong with alloca() ? David.Chase@Eng.Sun.COM (1991-12-23)
Re: What's wrong with alloca() ? pcg@aber.ac.uk (1991-12-26)
Re: What's wrong with alloca() ? wicklund@intellistor.com (1991-12-30)
Re: What's wrong with alloca() ? wws@renaissance.cray.com (1991-12-30)
Re: What's wrong with alloca() in gcc???? mo@gizmo.bellcore.com (1991-12-31)
Forward into the past! drw@kutta.mit.edu (1991-12-31)
Re: What's wrong with alloca() ? jfc@athena.mit.edu (1991-12-31)
Re: What's wrong with alloca() ? GORMAN_B@prime1.lancashire-poly.ac.uk (Barry Gorman) (1992-01-03)
Re: What's wrong with alloca() ? rankin@eql.caltech.edu (1992-01-05)
Re: What's wrong with alloca() ? pcg@aber.ac.uk (1992-01-05)
[2 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: wws@renaissance.cray.com (Walter Spector)
Keywords: storage
Organization: Compilers Central
References: 91-12-075 91-12-081
Date: Mon, 30 Dec 91 13:14:39 PST

Some compilers support arrays which are dynamically sized when a context
is entered. This is similar to a very useful Fortran-90 feature. It is
supported by the GNU C compiler. I think it is recommended approach by
the NCEG (Numerical C Extensions Group) too. E.g.,


void junk (int n)
{
int array[n];
...
{
int another1[n*2+13];
...
}
}


Note that the routines 'array' and 'another1' are local to routine 'junk'.
They are allocated upon entry (doesn't matter if it is the stack or heap)
and deallocated upon exit.


The above eliminates most, but not all, uses of alloca. It also avoids
some of the need for (C's unrestricted) pointers since you aren't calling
malloc and free - so allows better compiler optimization.


Alloca can be very tricky to implement on a machine where the stack is not
contiguous. The 'portable alloca', supplied with most GNU software fails
since the stack segments are then linked - but are not necessarily
top-down or bottom-up.


> (Piercarlo Grandi writes:)
> Actually alloca() and obstacks are variations on controlled storage
> allocation in PL/1. alloca() and obstacks come from people that almost
> certainly were using at some time Multics, and its PL/1 compiler.


This is very interesting!


Walt
--
Walt Spector
(wws@renaissance.cray.com)
Sunnyvale, California
_._ _._ _.... _. ._.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.