[Ccing bug-gnulib] Sam Steingold asked: > if I use alloca-opt from gnulib, can I replace > > #ifdef HAVE_ALLOCA > #define alloca __builtin_alloca > #elif defined(MICROSOFT) > #include <malloc.h> > #define alloca _alloca > #elif defined(HAVE_ALLOCA_H) > #include <alloca.h> > #ifndef alloca /* some define 'alloca' as macro... */ > #if !(defined(UNIX_OSF) || defined(UNIX_DEC_ULTRIX)) > /* OSF/1 V3 declares `alloca' as returning char*, but in OSF/1 V4 > it returns void*. I don't know how to distinguish the two. */ > extern_C void* alloca (int size); /* see MALLOC(3V) */ > #endif > #endif > #elif defined(_AIX) > #pragma alloca /* AIX requires this to be the first thing in the file. */ > #elif !defined(NO_ALLOCA) > extern_C void* alloca (int size); /* see MALLOC(3V) */ > #endif > > with something like > > #include <alloca.h> > #ifndef HAVE_ALLOCA > #if defined(MICROSOFT) > #include <malloc.h> > #define alloca _alloca > #elif defined(_AIX) > #pragma alloca /* AIX requires this to be the first thing in the file. */ > #elif !defined(NO_ALLOCA) > extern_C void* alloca (int size); /* see MALLOC(3V) */ > #endif > #endif > > of something even simpler?
Here's how you can find out: 1) The module description says: Description: Memory allocation on the stack, as an optional optimization. It allows using the alloca() macro if and only if the autoconf tests define HAVE_ALLOCA. ... Include: <alloca.h> So this means you should be able to write #include <alloca.h> #if HAVE_ALLOCA ... use alloca(n) ... #endif If you are still unsure: 2) Look at the unit test modules/alloca-opt-tests. It mentions a file tests/test-alloca-opt.c. When you look there, it indeed does #include <alloca.h> #if HAVE_ALLOCA ... use alloca(n) ... #endif So really this way of using alloca is tested. 3) Finally there is also documentation: <http://www.gnu.org/software/gnulib/manual/html_node/alloca_002dopt.html> Bruno -- In memoriam The victims of the Zaklopača massacre <http://greatersurbiton.wordpress.com/2010/02/12/interview-with-nihada-hodzic-survivor-of-the-zaklopaca-massacre/>