[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lwc-list] alloca?
Re: [Lwc-list] alloca?
Wed, 6 Aug 2003 15:54:45 +0300 (EET DST)
Well, first of all, alloca is a very good thing IMHO (definitelly better
than variable size arrays of C99). When we call alloca(x) the compiler
will just decrease the stack pointer by 'x' bytes. Pretty efficient and
leads to well structured programs if you try to take advantage of it.
lwc even supports the localloc operator to allocate+construct an
object with alloca. Maybe C should have a special "decrease stack"
operator in the first place.
> I've been trying to port lwc over to work with tcc and basically i'm
> getting killed by tcc's lack of alloca.
Yep, I've seen this.
I made an attempt to add alloca support to tcc but it wasn't so easy.
So there are two choices:
1. Wait until Bellard implements it
2. Use a library version of alloca.
I think  used to exist somewhere in glibc.
Maybe you have to #include<alloca.h>
I'll be looking for this. If you find a solution please post it here.
> The alloca function is machine and compiler dependent. Its
> use is discouraged.
While the stupid variable size arrays (who break the constness of
sizeof() and the constant offset of local objects) are better.
Who writes these man pages?
> On many systems alloca cannot be used inside the list of
> arguments of a function call, because the stack space
> reserved by alloca would appear on the stack in the middle
> of the space for the function arguments.
lwc compiler detects this and produces a parse error if alloca
is used in the middle of function arguments.
> Would it hurt anyone to just pretty much axe alloca calls? The 'c'
> mentality has always been to pair up your mallocs and frees and perhaps
> the alloca calls are just away to be lazy.
I think not.
When we need to allocate something that will only
be used by callees, like below
int foo ()
c = malloc()
alloca is a MUST. This is what the stack is for, there is no
need to pollute the data segment (introduce fragmentation?).
BTW. The current version of lwc has a serious design flaw in virtual
inheritance. The downcast data is not position independent and therefore
it is totally broken. This is being fixed right now. There are a couple
of other bugs which are fixed. Next version will be released in a week or