manpagez: man pages & more
info autoconf
Home | html | info | man

File: autoconf.info,  Node: Generic Declarations,  Prev: Declarations.php">Particular Declarations,  Up: Declarations

5.7.2 Generic Declaration Checks
--------------------------------

These macros are used to find declarations not covered by the
"particular" test macros.

 -- Macro: AC_CHECK_DECL (SYMBOL, [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
     If SYMBOL (a function, variable, or constant) is not declared in
     INCLUDES and a declaration is needed, run the shell commands
     ACTION-IF-NOT-FOUND, otherwise ACTION-IF-FOUND.  INCLUDES is a
     series of include directives, defaulting to ‘AC_INCLUDES_DEFAULT’
     (*note Default Includes::), which are used prior to the declaration
     under test.

     This macro actually tests whether SYMBOL is defined as a macro or
     can be used as an r-value, not whether it is really declared,
     because it is much safer to avoid introducing extra declarations
     when they are not needed.  In order to facilitate use of C++ and
     overloaded function declarations, it is possible to specify
     function argument types in parentheses for types which can be
     zero-initialized:

          AC_CHECK_DECL([basename(char *)])

     This macro caches its result in the ‘ac_cv_have_decl_SYMBOL’
     variable, with characters not suitable for a variable name mapped
     to underscores.

 -- Macro: AC_CHECK_DECLS (SYMBOLS, [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND], [INCLUDES = AC_INCLUDES_DEFAULT])
     For each of the SYMBOLS (_comma_-separated list with optional
     function argument types for C++ overloads), define
     ‘HAVE_DECL_SYMBOL’ (in all capitals) to ‘1’ if SYMBOL is declared,
     otherwise to ‘0’.  If ACTION-IF-NOT-FOUND is given, it is
     additional shell code to execute when one of the function
     declarations is needed, otherwise ACTION-IF-FOUND is executed.

     INCLUDES is a series of include directives, defaulting to
     ‘AC_INCLUDES_DEFAULT’ (*note Default Includes::), which are used
     prior to the declarations under test.

     This macro uses an M4 list as first argument:
          AC_CHECK_DECLS([strdup])
          AC_CHECK_DECLS([strlen])
          AC_CHECK_DECLS([malloc, realloc, calloc, free])
          AC_CHECK_DECLS([j0], [], [], [[#include ]])
          AC_CHECK_DECLS([[basename(char *)], [dirname(char *)]])

     Unlike the other ‘AC_CHECK_*S’ macros, when a SYMBOL is not
     declared, ‘HAVE_DECL_SYMBOL’ is defined to ‘0’ instead of leaving
     ‘HAVE_DECL_SYMBOL’ undeclared.  When you are _sure_ that the check
     was performed, use ‘HAVE_DECL_SYMBOL’ in ‘#if’:

          #if !HAVE_DECL_SYMBOL
          extern char *symbol;
          #endif

     If the test may have not been performed, however, because it is
     safer _not_ to declare a symbol than to use a declaration that
     conflicts with the system's one, you should use:

          #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
          void *malloc (size_t *s);
          #endif

     You fall into the second category only in extreme situations:
     either your files may be used without being configured, or they are
     used during the configuration.  In most cases the traditional
     approach is enough.

     This macro caches its results in ‘ac_cv_have_decl_SYMBOL’
     variables, with characters not suitable for a variable name mapped
     to underscores.

 -- Macro: AC_CHECK_DECLS_ONCE (SYMBOLS)
     For each of the SYMBOLS (_comma_-separated list), define
     ‘HAVE_DECL_SYMBOL’ (in all capitals) to ‘1’ if SYMBOL is declared
     in the default include files, otherwise to ‘0’.  This is a
     once-only variant of ‘AC_CHECK_DECLS’.  It generates the checking
     code at most once, so that ‘configure’ is smaller and faster; but
     the checks cannot be conditionalized and are always done once,
     early during the ‘configure’ run.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.