This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: alloca and c++
- From: Ingo Krabbe <i dot krabbe at dokom dot net>
- To: Devang Patel <dpatel at apple dot com>,Gabriel Dos Reis <gdr at codesourcery dot com>
- Cc: Devang Patel <dpatel at apple dot com>,gcc at gcc dot gnu dot org
- Date: Fri, 1 Feb 2002 23:51:24 +0100
- Subject: Re: alloca and c++
- Organization: ask (automatische system komponenten)
- References: <CB69DD33-1751-11D6-9970-00039310EDEA@apple.com>
I don't know what's the problem (g++ --version = 2.95.3)
(see attached code)
declaring a function in C++ scrambles its internal name as you can see if you
call "nm" on the produced executable. You have to declare it in extern "C".
This is done automatically by #include <stdlib.h> .. so lets look there :
#if defined __USE_GNU || defined __USE_BSD || defined __USE_MISC
# include <alloca.h>
#endif /* Use GNU, BSD, or misc. */
alloca is included only if you use GNU,BSD or misc extensions.
How you do this you can read about in features.h
This is done, because the standard use of alloca is discouraged as you can
read on the manual page.
Of course it should work if you declare it by hand. This works only if you
use extern "C".
CU INGO
#include <stdio.h>
extern "C" {
extern void* alloca( size_t );
}
extern int main( int, char** );
int main( int argc, char** argv )
{
char* s = (char*) alloca( 10 );
return 0;
}