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++


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;
}

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