autoconf: C Compiler

1 
1 5.10.3 C Compiler Characteristics
1 ---------------------------------
1 
1 The following macros provide ways to find and exercise a C Compiler.
1 There are a few constructs that ought to be avoided, but do not deserve
1 being checked for, since they can easily be worked around.
1 
1 Don't use lines containing solitary backslashes
1      They tickle a bug in the HP-UX C compiler (checked on HP-UX 10.20,
1      11.00, and 11i).  When given the following source:
1 
1           #ifdef __STDC__
1           /\
1           * A comment with backslash-newlines in it.  %{ %} *\
1           \
1           /
1           char str[] = "\\
1           " A string with backslash-newlines in it %{ %} \\
1           "";
1           char apostrophe = '\\
1           \
1           '\
1           ';
1           #endif
1 
1      the compiler incorrectly fails with the diagnostics
1      "Non-terminating comment at end of file" and "Missing `#endif' at
1      end of file."  Removing the lines with solitary backslashes solves
1      the problem.
1 
1 Don't compile several files at once if output matters to you
1      Some compilers, such as HP's, report names of files being compiled
1      when given more than one file operand.  For instance:
1 
1           $ cc a.c b.c
1           a.c:
1           b.c:
1 
1      This can cause problems if you observe the output of the compiler
1      to detect failures.  Invoking `cc -c a.c && cc -c b.c && cc -o c
1      a.o b.o' solves the issue.
1 
1 Don't rely on `#error' failing
1      The IRIX C compiler does not fail when #error is preprocessed; it
1      simply emits a diagnostic and continues, exiting successfully.  So,
1      instead of an error directive like `#error "Unsupported word size"'
1      it is more portable to use an invalid directive like `#Unsupported
1      word size' in Autoconf tests.  In ordinary source code, `#error' is
1      OK, since installers with inadequate compilers like IRIX can simply
1      examine these compilers' diagnostic output.
1 
1 Don't rely on correct `#line' support
1      On Solaris, `c89' (at least Sun C 5.3 through 5.8) diagnoses
1      `#line' directives whose line numbers are greater than 32767.
1      Nothing in Posix makes this invalid.  That is why Autoconf stopped
1      issuing `#line' directives.
1 
1  -- Macro: AC_PROG_CC ([COMPILER-SEARCH-LIST])
1      Determine a C compiler to use.  If `CC' is not already set in the
1      environment, check for `gcc' and `cc', then for other C compilers.
1      Set output variable `CC' to the name of the compiler found.
1 
1      This macro may, however, be invoked with an optional first argument
1      which, if specified, must be a blank-separated list of C compilers
1      to search for.  This just gives the user an opportunity to specify
1      an alternative search list for the C compiler.  For example, if
1      you didn't like the default order, then you could invoke
1      `AC_PROG_CC' like this:
1 
1           AC_PROG_CC([gcc cl cc])
1 
1      If the C compiler does not handle function prototypes correctly by
1      default, try to add an option to output variable `CC' to make it
1      so.  This macro tries various options that select
1      standard-conformance modes on various systems.
1 
1      After calling this macro you can check whether the C compiler has
1      been set to accept ANSI C89 (ISO C90); if not, the shell variable
1      `ac_cv_prog_cc_c89' is set to `no'.  See also `AC_C_PROTOTYPES'
1      below.
1 
1      If using the GNU C compiler, set shell variable `GCC' to `yes'.
1      If output variable `CFLAGS' was not already set, set it to `-g
1      -O2' for the GNU C compiler (`-O2' on systems where GCC does not
1      accept `-g'), or `-g' for other compilers.  If your package does
1      not like this default, then it is acceptable to insert the line `:
1      ${CFLAGS=""}' after `AC_INIT' and before `AC_PROG_CC' to select an
1      empty default instead.
1 
1      Many Autoconf macros use a compiler, and thus call
1      `AC_REQUIRE([AC_PROG_CC])' to ensure that the compiler has been
1      determined before the body of the outermost `AC_DEFUN' macro.
1      Although `AC_PROG_CC' is safe to directly expand multiple times, it
1      performs certain checks (such as the proper value of `EXEEXT') only
1      on the first invocation.  Therefore, care must be used when
1      invoking this macro from within another macro rather than at the
1      top level (⇒Expanded Before Required).
1 
1  -- Macro: AC_PROG_CC_C_O
1      If the C compiler does not accept the `-c' and `-o' options
1      simultaneously, define `NO_MINUS_C_MINUS_O'.  This macro actually
1      tests both the compiler found by `AC_PROG_CC', and, if different,
1      the first `cc' in the path.  The test fails if one fails.  This
1      macro was created for GNU Make to choose the default C compilation
1      rule.
1 
1      For the compiler COMPILER, this macro caches its result in the
1      `ac_cv_prog_cc_COMPILER_c_o' variable.
1 
1  -- Macro: AC_PROG_CPP
1      Set output variable `CPP' to a command that runs the C
1      preprocessor.  If `$CC -E' doesn't work, `/lib/cpp' is used.  It
1      is only portable to run `CPP' on files with a `.c' extension.
1 
1      Some preprocessors don't indicate missing include files by the
1      error status.  For such preprocessors an internal variable is set
1      that causes other macros to check the standard error from the
1      preprocessor and consider the test failed if any warnings have
1      been reported.  For most preprocessors, though, warnings do not
1      cause include-file tests to fail unless `AC_PROG_CPP_WERROR' is
1      also specified.
1 
1  -- Macro: AC_PROG_CPP_WERROR
1      This acts like `AC_PROG_CPP', except it treats warnings from the
1      preprocessor as errors even if the preprocessor exit status
1      indicates success.  This is useful for avoiding headers that
1      generate mandatory warnings, such as deprecation notices.
1 
1    The following macros check for C compiler or machine architecture
1 features.  To check for characteristics not listed here, use
1 `AC_COMPILE_IFELSE' (⇒Running the Compiler) or `AC_RUN_IFELSE'
1 (⇒Runtime).
1 
1  -- Macro: AC_PROG_CC_STDC
1      If the C compiler cannot compile ISO Standard C (currently C99),
1      try to add an option to output variable `CC' to make it work.  If
1      the compiler does not support C99, fall back to supporting ANSI
1      C89 (ISO C90).
1 
1      After calling this macro you can check whether the C compiler has
1      been set to accept Standard C; if not, the shell variable
1      `ac_cv_prog_cc_stdc' is set to `no'.
1 
1  -- Macro: AC_PROG_CC_C89
1      If the C compiler is not in ANSI C89 (ISO C90) mode by default,
1      try to add an option to output variable `CC' to make it so.  This
1      macro tries various options that select ANSI C89 on some system or
1      another, preferring extended functionality modes over strict
1      conformance modes.  It considers the compiler to be in ANSI C89
1      mode if it handles function prototypes correctly.
1 
1      After calling this macro you can check whether the C compiler has
1      been set to accept ANSI C89; if not, the shell variable
1      `ac_cv_prog_cc_c89' is set to `no'.
1 
1      This macro is called automatically by `AC_PROG_CC'.
1 
1  -- Macro: AC_PROG_CC_C99
1      If the C compiler is not in C99 mode by default, try to add an
1      option to output variable `CC' to make it so.  This macro tries
1      various options that select C99 on some system or another,
1      preferring extended functionality modes over strict conformance
1      modes.  It considers the compiler to be in C99 mode if it handles
1      `_Bool', `//' comments, flexible array members, `inline', signed
1      and unsigned `long long int', mixed code and declarations, named
1      initialization of structs, `restrict', `va_copy', varargs macros,
1      variable declarations in `for' loops, and variable length arrays.
1 
1      After calling this macro you can check whether the C compiler has
1      been set to accept C99; if not, the shell variable
1      `ac_cv_prog_cc_c99' is set to `no'.
1 
1  -- Macro: AC_C_BACKSLASH_A
1      Define `HAVE_C_BACKSLASH_A' to 1 if the C compiler understands
1      `\a'.
1 
1      This macro is obsolescent, as current C compilers understand `\a'.
1      New programs need not use this macro.
1 
1  -- Macro: AC_C_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE],
1           [ACTION-IF-UNKNOWN], [ACTION-IF-UNIVERSAL])
1      If words are stored with the most significant byte first (like
1      Motorola and SPARC CPUs), execute ACTION-IF-TRUE.  If words are
1      stored with the least significant byte first (like Intel and VAX
1      CPUs), execute ACTION-IF-FALSE.
1 
1      This macro runs a test-case if endianness cannot be determined
1      from the system header files.  When cross-compiling, the test-case
1      is not run but grep'ed for some magic values.  ACTION-IF-UNKNOWN
1      is executed if the latter case fails to determine the byte sex of
1      the host system.
1 
1      In some cases a single run of a compiler can generate code for
1      multiple architectures.  This can happen, for example, when
1      generating Mac OS X universal binary files, which work on both
1      PowerPC and Intel architectures.  In this case, the different
1      variants might be for different architectures whose endiannesses
1      differ.  If `configure' detects this, it executes
1      ACTION-IF-UNIVERSAL instead of ACTION-IF-UNKNOWN.
1 
1      The default for ACTION-IF-TRUE is to define `WORDS_BIGENDIAN'.
1      The default for ACTION-IF-FALSE is to do nothing.  The default for
1      ACTION-IF-UNKNOWN is to abort configure and tell the installer how
1      to bypass this test.  And finally, the default for
1      ACTION-IF-UNIVERSAL is to ensure that `WORDS_BIGENDIAN' is defined
1      if and only if a universal build is detected and the current code
1      is big-endian; this default works only if `autoheader' is used
1      (⇒autoheader Invocation).
1 
1      If you use this macro without specifying ACTION-IF-UNIVERSAL, you
1      should also use `AC_CONFIG_HEADERS'; otherwise `WORDS_BIGENDIAN'
1      may be set incorrectly for Mac OS X universal binary files.
1 
1  -- Macro: AC_C_CONST
1      If the C compiler does not fully support the `const' keyword,
1      define `const' to be empty.  Some C compilers that do not define
1      `__STDC__' do support `const'; some compilers that define
1      `__STDC__' do not completely support `const'.  Programs can simply
1      use `const' as if every C compiler supported it; for those that
1      don't, the makefile or configuration header file defines it as
1      empty.
1 
1      Occasionally installers use a C++ compiler to compile C code,
1      typically because they lack a C compiler.  This causes problems
1      with `const', because C and C++ treat `const' differently.  For
1      example:
1 
1           const int foo;
1 
1      is valid in C but not in C++.  These differences unfortunately
1      cannot be papered over by defining `const' to be empty.
1 
1      If `autoconf' detects this situation, it leaves `const' alone, as
1      this generally yields better results in practice.  However, using a
1      C++ compiler to compile C code is not recommended or supported, and
1      installers who run into trouble in this area should get a C
1      compiler like GCC to compile their C code.
1 
1      This macro caches its result in the `ac_cv_c_const' variable.
1 
1      This macro is obsolescent, as current C compilers support `const'.
1      New programs need not use this macro.
1 
1  -- Macro: AC_C_RESTRICT
1      If the C compiler recognizes a variant spelling for the `restrict'
1      keyword (`__restrict', `__restrict__', or `_Restrict'), then
1      define `restrict' to that; this is more likely to do the right
1      thing with compilers that support language variants where plain
1      `restrict' is not a keyword.  Otherwise, if the C compiler
1      recognizes the `restrict' keyword, don't do anything.  Otherwise,
1      define `restrict' to be empty.  Thus, programs may simply use
1      `restrict' as if every C compiler supported it; for those that do
1      not, the makefile or configuration header defines it away.
1 
1      Although support in C++ for the `restrict' keyword is not
1      required, several C++ compilers do accept the keyword.  This macro
1      works for them, too.
1 
1      This macro caches `no' in the `ac_cv_c_restrict' variable if
1      `restrict' is not supported, and a supported spelling otherwise.
1 
1  -- Macro: AC_C_VOLATILE
1      If the C compiler does not understand the keyword `volatile',
1      define `volatile' to be empty.  Programs can simply use `volatile'
1      as if every C compiler supported it; for those that do not, the
1      makefile or configuration header defines it as empty.
1 
1      If the correctness of your program depends on the semantics of
1      `volatile', simply defining it to be empty does, in a sense, break
1      your code.  However, given that the compiler does not support
1      `volatile', you are at its mercy anyway.  At least your program
1      compiles, when it wouldn't before.  ⇒Volatile Objects, for
1      more about `volatile'.
1 
1      In general, the `volatile' keyword is a standard C feature, so you
1      might expect that `volatile' is available only when `__STDC__' is
1      defined.  However, Ultrix 4.3's native compiler does support
1      volatile, but does not define `__STDC__'.
1 
1      This macro is obsolescent, as current C compilers support
1      `volatile'.  New programs need not use this macro.
1 
1  -- Macro: AC_C_INLINE
1      If the C compiler supports the keyword `inline', do nothing.
1      Otherwise define `inline' to `__inline__' or `__inline' if it
1      accepts one of those, otherwise define `inline' to be empty.
1 
1  -- Macro: AC_C_CHAR_UNSIGNED
1      If the C type `char' is unsigned, define `__CHAR_UNSIGNED__',
1      unless the C compiler predefines it.
1 
1      These days, using this macro is not necessary.  The same
1      information can be determined by this portable alternative, thus
1      avoiding the use of preprocessor macros in the namespace reserved
1      for the implementation.
1 
1           #include <limits.h>
1           #if CHAR_MIN == 0
1           # define CHAR_UNSIGNED 1
1           #endif
1 
1  -- Macro: AC_C_STRINGIZE
1      If the C preprocessor supports the stringizing operator, define
1      `HAVE_STRINGIZE'.  The stringizing operator is `#' and is found in
1      macros such as this:
1 
1           #define x(y) #y
1 
1      This macro is obsolescent, as current C compilers support the
1      stringizing operator.  New programs need not use this macro.
1 
1  -- Macro: AC_C_FLEXIBLE_ARRAY_MEMBER
1      If the C compiler supports flexible array members, define
1      `FLEXIBLE_ARRAY_MEMBER' to nothing; otherwise define it to 1.
1      That way, a declaration like this:
1 
1           struct s
1             {
1               size_t n_vals;
1               double val[FLEXIBLE_ARRAY_MEMBER];
1             };
1 
1      will let applications use the "struct hack" even with compilers
1      that do not support flexible array members.  To allocate and use
1      such an object, you can use code like this:
1 
1           size_t i;
1           size_t n = compute_value_count ();
1           struct s *p =
1              malloc (offsetof (struct s, val)
1                      + n * sizeof (double));
1           p->n_vals = n;
1           for (i = 0; i < n; i++)
1             p->val[i] = compute_value (i);
1 
1  -- Macro: AC_C_VARARRAYS
1      If the C compiler supports variable-length arrays, define
1      `HAVE_C_VARARRAYS'.  A variable-length array is an array of
1      automatic storage duration whose length is determined at run time,
1      when the array is declared.
1 
1  -- Macro: AC_C_TYPEOF
1      If the C compiler supports GCC's `typeof' syntax either directly or
1      through a different spelling of the keyword (e.g., `__typeof__'),
1      define `HAVE_TYPEOF'.  If the support is available only through a
1      different spelling, define `typeof' to that spelling.
1 
1  -- Macro: AC_C_PROTOTYPES
1      If function prototypes are understood by the compiler (as
1      determined by `AC_PROG_CC'), define `PROTOTYPES' and
1      `__PROTOTYPES'.  Defining `__PROTOTYPES' is for the benefit of
1      header files that cannot use macros that infringe on user name
1      space.
1 
1      This macro is obsolescent, as current C compilers support
1      prototypes.  New programs need not use this macro.
1 
1  -- Macro: AC_PROG_GCC_TRADITIONAL
1      Add `-traditional' to output variable `CC' if using the GNU C
1      compiler and `ioctl' does not work properly without
1      `-traditional'.  That usually happens when the fixed header files
1      have not been installed on an old system.
1 
1      This macro is obsolescent, since current versions of the GNU C
1      compiler fix the header files automatically when installed.
1