Previous: , Up: Common Behavior   [Contents][Index]


5.1.2 Default Includes

Test programs frequently need to include headers that may or may not be available on the system whose features are being tested. Each test can use all the preprocessor macros that have been AC_DEFINEd by previous tests, so for example one may write

#include <time.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif

if sys/time.h has already been tested for.

All hosted environments that are still of interest for portable code provide all of the headers specified in ISO C90 (as amended in 1995): assert.h, ctype.h, errno.h, float.h, iso646.h, limits.h, locale.h, math.h, setjmp.h, signal.h, stdarg.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, wchar.h, and wctype.h. Most programs can safely include these headers unconditionally. All other headers, including all headers from later revisions of the C standard, need to be tested for (see Header Files).

If your program needs to be portable to a freestanding environment, such as an embedded OS that doesn’t provide all of the facilities of the C90 standard library, you may need to test for some of the above headers as well. Note that many Autoconf macros internally assume that the complete set of C90 headers are available.

Most generic macros use the following macro to provide a default set of includes:

Macro: AC_INCLUDES_DEFAULT ([include-directives])

Expand to include-directives if present and nonempty, otherwise to:

#include <stddef.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#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

Using this macro without include-directives has the side effect of checking for stdio.h, stdlib.h, string.h, inttypes.h, stdint.h, strings.h, sys/types.h, sys/stat.h, and unistd.h, as if by AC_CHECK_HEADERS_ONCE. For backward compatibility, the macro STDC_HEADERS will be defined when both stdlib.h and string.h are available.

Portability Note: It is safe for most programs to assume the presence of all of the headers required by the original 1990 C standard. AC_INCLUDES_DEFAULT checks for stdio.h, stdlib.h, and 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 ‘#ifdef HAVE_STDIO_H’ in your own code.

inttypes.h and stdint.h were added to C in the 1999 revision of the standard, and strings.h, sys/types.h, sys/stat.h, and unistd.h are POSIX extensions. You should guard uses of these headers with appropriate conditionals.

Macro: AC_CHECK_INCLUDES_DEFAULT

Check for all the headers that AC_INCLUDES_DEFAULT would check for as a side-effect, if this has not already happened.

This macro mainly exists so that autoupdate can replace certain obsolete constructs with it. You should not need to use it yourself; in fact, it is likely to be safe to delete it from any script in which it appears. (autoupdate does not know whether preprocessor macros such as HAVE_STDINT_H are used in the program, nor whether they would get defined as a side-effect of other checks.)


Previous: Standard Symbols, Up: Common Behavior   [Contents][Index]