This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: alloca and c++



On Friday, February 1, 2002, at 12:12  PM, Gabriel Dos Reis wrote:

> Devang Patel <dpatel@apple.com> writes:
>
> | Hello,
> |
> | Following gives me undefined  (not undeclared) 'alloca' error in C++.
> | Is it expected ?
>
> Yes.
>
> Alloca() is not a standard function.  And on systems I've seen it used,
> the appropriate header was included.

Yes. On the darwin system, stdlib.h provides the alloca. But the results 
are same.
I tried again.
[bardoli:/Volumes/Sandbox/Testing/gcc3]$ cat test_alloca.cc
#include <stdlib.h>

int main()
{
         char *s = (char *) alloca (10);
         return 0;
}

[bardoli:/Volumes/Sandbox/Testing/gcc3]$ /usr/gcc3/bin/g++ test_alloca.cc
ld: Undefined symbols:
_alloca

I am *not* getting, undeclared alloca error. Which I do get
if I do not include <stdlib.h> or do not provide alloca() declaration.

> | Or am I suppose to use __builtin_alloca()  to get gcc-built-in 
> alloca()
> | in C++ source ?
>
> Certainly.

So, my question is :
Even though I include stdilib.h,
I can not use alloca() in c++ and I must use __builtin_alloca().
Is it True ?

> And declaring standard functions "by hand" is evil.  Use appropriate
> header for that.

I know. I did it to simplify the test case.
(And to probably to avoid answers that my stdlib.h might not have 
alloca()...)

Thank you,
Devang


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]