Page 1 of 1
alloca() ?
Posted: Sun Sep 26, 2004 10:44 am
by Maddas
Hi.
I'm trying to use alloca() in a program but every time I do, I get a compiler error. Isn't it in stdlib.h? How can I use it, and if not, why is it forbidden?
Thanks, Maddas
Posted: Sun Sep 26, 2004 11:01 am
by shamim
I think the compiler you use support this, but it is not supported by ANSI C.
Posted: Sun Sep 26, 2004 11:51 am
by Krzysztof Duleba
alloca is defined in <alloca.h>.
Posted: Sun Sep 26, 2004 12:18 pm
by Maddas
Thanks, my manpage said it was in either alloca.h and stdlib.h

Posted: Sun Sep 26, 2004 12:44 pm
by Krzysztof Duleba
Not really. Alloca is not ansi or posix and therefore it should not be defined in stdlib.h. However, stdlib.h usually includes alloca.h. I guess that OJ is using strict ansi option and in that case you have to include alloca.h manually (and still it can cause some problems):
BUGS
The alloca function is machine and compiler dependent. On many systems
its implementation is buggy. Its use is discouraged.
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.