Hi all,

The Autoconf manual (section 5.5.2, "Particular Function Checks")
recommends the following check for source files that use the alloca()
function:

    #ifdef HAVE_ALLOCA_H
    # include <alloca.h>
    #elif defined __GNUC__
    # define alloca __builtin_alloca
    #elif defined _AIX
    # define alloca __alloca
    #elif defined _MSC_VER
    # include <malloc.h>
    # define alloca _alloca
    #else
    # include <stddef.h>
    # ifdef  __cplusplus
    extern "C"
    # endif
    void *alloca (size_t);
    #endif

There are systems where this breaks though, because alloca() is
available as a function but not in a special 'alloca.h' header file.
For example, in FreeBSD, alloca() is defined in 'stdlib.h' and this
means that HAVE_ALLOCA_H is undefined.  The result of the previous macro
bits is that a redundant prototype of alloca() is declared.

The modified version shown below declares a prototype of alloca() only
when HAVE_ALLOCA is unset/undefined regardless of what HAVE_ALLOCA_H is
set to:

    #ifdef HAVE_ALLOCA_H
    # include <alloca.h>
    #elif !defined(HAVE_ALLOCA)
    # if defined __GNUC__
    #  define alloca __builtin_alloca
    # elif defined _AIX
    #  define alloca __alloca
    # else
    #  include <stddef.h>
    #  ifdef  __cplusplus
    extern "C"
    #  endif
    void *alloca (size_t);
    # endif
    #endif

This fixes the alloca() related warnings of at least GNU Emacs on my
FreeBSD installations.  I've submitted the relevant changes to the GNU
Emacs maintainers, but if we can fix the example in the autoconf manual
too it would be really nice.


Reply via email to