alloca() ?

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
Maddas
New poster
Posts: 11
Joined: Sat Apr 03, 2004 1:45 am

alloca() ?

Post 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
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

I think the compiler you use support this, but it is not supported by ANSI C.
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

alloca is defined in <alloca.h>.
Maddas
New poster
Posts: 11
Joined: Sat Apr 03, 2004 1:45 am

Post by Maddas »

Thanks, my manpage said it was in either alloca.h and stdlib.h :-)
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post 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.
Post Reply

Return to “C”