+2000-02-15 Akim Demaille <akim@epita.fr>
+
+ Define HAVE_DECL_FOO both to 1 if found and 0 otherwise.
+
+ * acgeneral.m4 (AC_CHECK_DECLS): Define HAVE_DECL_FOO to 1 instead
+ of NEED_FOO_DECL if found. Define to 0 if not found.
+ * autoheader.m4 (AC_CHECK_DECLS): Template HAVE_DECL_FOO.
+ * tests/semantics.m4 (AC_CHECK_DECLS): Adjusted.
+ * doc/autoconf.texi (Generic Declarations): Adjusted.
+
2000-02-15 Akim Demaille <akim@epita.fr>
* doc/autoconf.texi (Generic Structures):
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
# [INCLUDES])
# --------------------------------------------------------
+# Defines HAVE_DECL_SYMBOL to 1 if declared, 0 otherwise. See the
+# documentation for a detailed explanation of this difference with
+# other AC_CHECK_*S macros.
AC_DEFUN([AC_CHECK_DECLS],
[m4_foreach([AC_Symbol], [$1],
[AC_SPECIALIZE([AC_CHECK_DECL], AC_Symbol,
- [$2],
- [AC_DEFINE_UNQUOTED(AC_TR_CPP([NEED_]AC_Symbol[_DECL]))
+ [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 1)
+$2],
+ [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 0)
$3],
[$4])])
])# AC_CHECK_DECLS
@defmac AC_CHECK_DECLS ((@var{symbol}, @dots{}), @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
@maindex CHECK_DECLS
-@cvindex NEED_@var{symbol}_DECL
+@cvindex HAVE_DECL_@var{symbol}
For each given @var{symbol} (comma separated list), define
-@code{NEED_@var{symbol}_DECL} (in all capitals) if @var{symbol} has to
-be declared to be used as an r-value. If @var{action-if-not-found} is
-given, it is additional shell code to execute when one of the function
-declarations is needed, otherwise @var{action-if-found} is executed.
+@code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
+@var{symbol} is declared, otherwise to @samp{0}. If
+@var{action-if-not-found} is given, it is additional shell code to
+execute when one of the function declarations is needed, otherwise
+@var{action-if-found} is executed.
This macro uses an m4 list as first argument:
@example
AC_CHECK_DECLS((malloc, realloc, calloc, free))
@end example
-This macro does not define @code{HAVE_@var{symbol}_DECL} on purpose.
-The following code
+Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
+declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
+of leaving @code{HAVE_DECL_@var{symbol}} undeclared.
+
+When you are @emph{sure} that the check was performed, use
+@code{HAVE_DECL_@var{symbol}} just like any other result of Autoconf:
+
@example
-#if NEED_FOO_DECL
-/* Declare foo. */
+#if !HAVE_DECL_SYMBOL
+extern char *symbol;
#endif
@end example
-is safer than
+
+@noindent
+But if the test may have not been performed, because it is safer
+@emph{not} to declare a symbol than to use a declaration which conflicts
+with the system's one, you should use:
+
@example
-#if !HAVE_FOO_DECL
-/* Declare foo. */
+#if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
+char *malloc (size_t *s);
#endif
@end example
-since in this last case, if @code{configure} was not run, then the test
-succeeds, thus @code{foo} is declared, with risks to clash with previous
-declarations. It is safer not to declare in case of doubts.
+
+@noindent
+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.
@end defmac
AH_DEFUN([AC_CHECK_DECLS],
[m4_foreach([AC_Symbol], [$1],
- [AH_TEMPLATE(AC_TR_CPP([NEED_]AC_Symbol[_DECL]),
- [Define if you need the declaration of `]AC_Symbol['.])
+ [AH_TEMPLATE(AC_TR_CPP([HAVE_DECL_]AC_Symbol),
+ [Define to 1 if you have the declaration of `]AC_Symbol[',
+ and to 0 if you don't.])
# Success
$2
# Failure
@defmac AC_CHECK_DECLS ((@var{symbol}, @dots{}), @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{includes})
@maindex CHECK_DECLS
-@cvindex NEED_@var{symbol}_DECL
+@cvindex HAVE_DECL_@var{symbol}
For each given @var{symbol} (comma separated list), define
-@code{NEED_@var{symbol}_DECL} (in all capitals) if @var{symbol} has to
-be declared to be used as an r-value. If @var{action-if-not-found} is
-given, it is additional shell code to execute when one of the function
-declarations is needed, otherwise @var{action-if-found} is executed.
+@code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
+@var{symbol} is declared, otherwise to @samp{0}. If
+@var{action-if-not-found} is given, it is additional shell code to
+execute when one of the function declarations is needed, otherwise
+@var{action-if-found} is executed.
This macro uses an m4 list as first argument:
@example
AC_CHECK_DECLS((malloc, realloc, calloc, free))
@end example
-This macro does not define @code{HAVE_@var{symbol}_DECL} on purpose.
-The following code
+Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
+declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
+of leaving @code{HAVE_DECL_@var{symbol}} undeclared.
+
+When you are @emph{sure} that the check was performed, use
+@code{HAVE_DECL_@var{symbol}} just like any other result of Autoconf:
+
@example
-#if NEED_FOO_DECL
-/* Declare foo. */
+#if !HAVE_DECL_SYMBOL
+extern char *symbol;
#endif
@end example
-is safer than
+
+@noindent
+But if the test may have not been performed, because it is safer
+@emph{not} to declare a symbol than to use a declaration which conflicts
+with the system's one, you should use:
+
@example
-#if !HAVE_FOO_DECL
-/* Declare foo. */
+#if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
+char *malloc (size_t *s);
#endif
@end example
-since in this last case, if @code{configure} was not run, then the test
-succeeds, thus @code{foo} is declared, with risks to clash with previous
-declarations. It is safer not to declare in case of doubts.
+
+@noindent
+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.
@end defmac
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
# [INCLUDES])
# --------------------------------------------------------
+# Defines HAVE_DECL_SYMBOL to 1 if declared, 0 otherwise. See the
+# documentation for a detailed explanation of this difference with
+# other AC_CHECK_*S macros.
AC_DEFUN([AC_CHECK_DECLS],
[m4_foreach([AC_Symbol], [$1],
[AC_SPECIALIZE([AC_CHECK_DECL], AC_Symbol,
- [$2],
- [AC_DEFINE_UNQUOTED(AC_TR_CPP([NEED_]AC_Symbol[_DECL]))
+ [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 1)
+$2],
+ [AC_DEFINE_UNQUOTED(AC_TR_CPP([HAVE_DECL_]AC_Symbol), 0)
$3],
[$4])])
])# AC_CHECK_DECLS
[AC_CHECK_DECLS((yes, no),,,
[int yes = 1;])],
[AT_CHECK_DEFINES(
-[#define NEED_NO_DECL 1
-/* #undef NEED_YES_DECL */
+[#define HAVE_DECL_NO 0
+#define HAVE_DECL_YES 1
])])