summaryrefslogtreecommitdiff
path: root/doc/autoconf.texi
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-12-06 11:40:39 -0500
committerZack Weinberg <zackw@panix.com>2020-12-06 11:40:39 -0500
commitb045574cb2ea1c8441be7a7b56fd471d704ebf3a (patch)
tree4e93553716d40939551f142b3b2121f5cbe59a42 /doc/autoconf.texi
parentc467efab94cd2d0331655d68d067fa0719fc8762 (diff)
downloadautoconf-b045574cb2ea1c8441be7a7b56fd471d704ebf3a.tar.gz
AC_INCLUDES_DEFAULT: Check for presence of C90 hosted headers (#110393)
Since 1993, Autoconf has been assuming that it is safe to include any of the headers defined by ISO C90 without checking for them; this is inaccurate, since only a subset are necessarily available in a C90 *freestanding* environment. It is OK to assume the presence of a header in a macro that checks specifically for something declared by that header (if the header is not present, we will think the specific declaration is unavailable, which is probably accurate for modern embedded environments). It is also OK to continue recommending that user code use these headers unconditionally—anyone working with a freestanding environment knows it. But it is not OK for very generic code within Autoconf itself, such as AC_INCLUDES_DEFAULT, to make this assumption. Note that the set of headers that are not always available includes stdio.h, which we have been assuming can be included unconditionally for even longer. In AC_INCLUDES_DEFAULT, revert to checking for string.h and stdlib.h before including them. Also revert to defining STDC_HEADERS only when string.h and stdlib.h are available (but do not check for float.h and stdarg.h, as these are part of the freestanding set). Add a new check for stdio.h. Sort the inclusion list by standard (C90 freestanding; C90 hosted; C99; POSIX) and alphabetically within each group. Revise all the documentation and update the testsuite. This partially reverts commit 86c213d0e355296f026a36e3203c0813041aae89 and is a partial fix for bug #110393. * lib/autoconf/headers.m4 (AC_CHECK_INCLUDES_DEFAULT): Check for stdio.h, stdlib.h, and string.h before including them. Define STDC_HEADERS only when string.h and stdlib.h are both available. Organize includes list by standard, then alphabetically. * doc/autoconf.texi, NEWS: Update to match. * tests/local.at (AT_CHECK_DEFINES): Make regexes more specific. Also expect a definition of HAVE_STDIO_H. * tests/c.at, tests/semantics.at, tests/tools.at: Use <float.h>, not <stdio.h>, as a header that we expect always to exist. Add HAVE_STDIO_H to various lists of macros that are expected to appear in config.h.
Diffstat (limited to 'doc/autoconf.texi')
-rw-r--r--doc/autoconf.texi50
1 files changed, 35 insertions, 15 deletions
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 01af2b29..cdd056c5 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -4070,17 +4070,14 @@ Expand to @var{include-directives} if present and nonempty, otherwise to:
@example
@group
#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
#endif
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
#endif
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
@@ -4088,6 +4085,15 @@ Expand to @var{include-directives} if present and nonempty, otherwise to:
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@@ -4095,12 +4101,26 @@ Expand to @var{include-directives} if present and nonempty, otherwise to:
@end example
Using this macro without @var{include-directives} has the side effect of
-checking for @file{sys/types.h}, @file{sys/stat.h}, @file{strings.h},
-@file{inttypes.h}, @file{stdint.h}, and @file{unistd.h}, as if by
-@code{AC_CHECK_HEADERS}. For backward compatibility's sake, it also
-unconditionally defines @code{HAVE_STRING_H}, @code{HAVE_STDLIB_H}, and
-@code{STDC_HEADERS}. New code should not make use of these preprocessor
-macros.
+checking for @file{stdio.h}, @file{stdlib.h}, @file{string.h},
+@file{inttypes.h}, @file{stdint.h}, @file{strings.h},
+@file{sys/types.h}, @file{sys/stat.h}, and @file{unistd.h}, as if by
+@code{AC_CHECK_HEADERS_ONCE}. For backward compatibility, the macro
+@code{STDC_HEADERS} will be defined when both @file{stdlib.h} and
+@file{string.h} are available.
+
+@strong{Portability Note:} It is safe for most programs to assume the
+presence of all of the headers required by the original 1990 C standard.
+@code{AC_INCLUDES_DEFAULT} checks for @file{stdio.h}, @file{stdlib.h},
+and @file{string.h}, even though they are in that list, because they
+might not be available when compiling for a ``freestanding environment''
+(in which most of the features of the C library are optional). You
+probably do not need to write @samp{#ifdef HAVE_STDIO_H} in your own
+code.
+
+@file{inttypes.h} and @file{stdint.h} were added to C in the 1999
+revision of the standard, and @file{strings.h}, @file{sys/types.h},
+@file{sys/stat.h}, and @file{unistd.h} are POSIX extensions. You
+@emph{should} guard uses of these headers with appropriate conditionals.
@end defmac
@defmac AC_CHECK_INCLUDES_DEFAULT