Re: What's wrong with alloca() ?

pcg@aber.ac.uk (Piercarlo Grandi)
Sun, 5 Jan 1992 22:08:10 GMT

          From comp.compilers

Related articles
[6 earlier articles]
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() ? 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)
Re: What's wrong with alloca() ? barmar@think.com (1992-01-06)
| List of all articles for this month |

Newsgroups: comp.compilers,comp.unix.aix
From: pcg@aber.ac.uk (Piercarlo Grandi)
Keywords: storage, design
Organization: Coleg Prifysgol Cymru
References: 91-12-075 92-01-017
Date: Sun, 5 Jan 1992 22:08:10 GMT

On 5 Jan 92 02:55:00 GMT, rankin@eql.caltech.edu (Pat Rankin) said:


[ ... how to implement alloca ... ]


rankin> Your method breaks when used with VAX C (DEC's C compiler for
rankin> VMS). Local variables can be reached with either a positive
rankin> offset from the stack pointer or a negative offset from the
rankin> frame pointer. [ ... trouble .. ] In other words, compiler
rankin> support _is_ required even though anybody could code their own
rankin> alloca() implementation.


Actually, damnit, some compilers do support alloca() and then botch it. I
have been trying to understand how it is that AIX 3.1.5 xlc (which has a
#pragma alloca to tell the compiler to exit a function popping the stack
in the neatest way) botches it (but only when optimizing), but it is
fairly hard.


Many problems could be solved if alloca() were consistently replaced by an
obstack() implementation, and I might well do such a thing eventually,
orif the original BCPL stack allocation procedure were used; I don't
remember the exact name, ir was something like (in C):


void withvector(proc,bytes)
void (*proc)(/* char *, unsigned */);
unsigned bytes;


of which a possible, inefficient implementation is:


{
char *vector = malloc(bytes);


proc(vector,bytes);


if (vector)
free(vector);
}


In other words, call the first parameter passing it a pointer to a dynamic
array and its size. At times a bit clumsy, but clear and easy to implement
safely.
--
Piercarlo Grandi | ARPA: pcg%uk.ac.aber@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@aber.ac.uk
--


Post a followup to this message

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