Index: NEWS =================================================================== RCS file: /cvsroot/autoconf/autoconf/NEWS,v retrieving revision 1.333 diff -u -r1.333 NEWS --- NEWS 17 Dec 2004 16:17:18 -0000 1.333 +++ NEWS 29 Dec 2004 17:05:51 -0000 @@ -1,5 +1,17 @@ * Major changes in Autoconf 2.59c +** AC_PROG_CC_C89, AC_PROG_CC_C99 + New macros for ISO C99 support. _AC_PROG_CC_STDC has been renamed + to AC_PROG_CC_C89. The shell variable ac_cv_prog_cc_stdc has been + renamed to ac_cv_prog_cc_c89 to reflect its more precise role. + +** AC_PROG_CC_STDC + Has been unobsoleted, and will check if the compiler supports ISO + C99, falling back to ANSI C89 if not. ac_cv_prog_cc_stdc is + retained for backwards compatibility, assuming the value of + ac_cv_prog_cc_c99 or ac_cv_prog_cc_c89 (whichever is valid, in + that order). + * Major changes in Autoconf 2.59b Released 2004-08-20, by Paul Eggert. Index: doc/autoconf.texi =================================================================== RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v retrieving revision 1.857 diff -u -r1.857 autoconf.texi --- doc/autoconf.texi 22 Dec 2004 21:50:08 -0000 1.857 +++ doc/autoconf.texi 29 Dec 2004 17:06:09 -0000 @@ -4594,8 +4594,8 @@ @item @file{inttypes.h} vs.@: @file{stdint.h} @hdrindex{inttypes.h} @hdrindex{stdint.h} -Paul Eggert notes that: ISO C 1999 says that @file{inttypes.h} includes address@hidden, so there's no need to include @file{stdint.h} +Paul Eggert notes that: @acronym{ISO} C 1999 says that @file{inttypes.h} +includes @file{stdint.h}, so there's no need to include @file{stdint.h} separately in a standard environment. Many implementations have @file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but I don't know of any implementation that has @file{stdint.h} but not @@ -5605,7 +5605,7 @@ After calling this macro you can check whether the C compiler has been set to accept @acronym{ANSI} C; if not, the shell variable address@hidden is set to @samp{no}. If you wrote your source address@hidden is set to @samp{no}. If you wrote your source code in @acronym{ANSI} C, you can make an address@hidden copy of it by using the program @code{ansi2knr}, which comes with Automake. See also under @code{AC_C_PROTOTYPES} below. @@ -5659,6 +5659,49 @@ @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or @code{AC_RUN_IFELSE} (@pxref{Run Time}). address@hidden AC_PROG_CC_STDC address@hidden +If the C compiler is not able to compile @acronym{ISO} Standard C +(currently @acronym{ISO} C99), try to add an option to output variable address@hidden to make it so. If the compiler does not support address@hidden C99, fall back to supporting @acronym{ANSI} C89 +(@acronym{ISO} C90). + +After calling this macro you can check whether the C compiler has been +set to accept @acronym{ISO} Standard C; if not, the shell variable address@hidden is set to @samp{no}. address@hidden defmac + address@hidden AC_PROG_CC_C89 address@hidden +If the C compiler is not in @acronym{ANSI} C89 (@acronym{ISO} C90) mode +by default, try to add an option to output variable @code{CC} to make +it so. This macro tries various options that select @acronym{ANSI} C89 +on some system or another. It considers the compiler to be in address@hidden C89 mode if it handles function prototypes correctly. + +After calling this macro you can check whether the C compiler has been +set to accept @acronym{ANSI} C89 C; if not, the shell variable address@hidden is set to @samp{no}. + +This macro is called automatically by @code{AC_PROG_CC}. address@hidden defmac + address@hidden AC_PROG_CC_C99 address@hidden +If the C compiler is not in @acronym{ISO} C99 C mode by default, try to +add an option to output variable @code{CC} to make it so. This macro +tries various options that select @acronym{ISO} C99 C on some system or +another. It considers the compiler to be in @acronym{ISO} C99 C mode +if it handles _Bool, flexible arrays, inline, long long, mixed code and +declarations, named initialization of structs, restrict, varargs macros, +variable declarations in for loops and variable length arrays. + +After calling this macro you can check whether the C compiler has been +set to accept @acronym{ISO} C99 C; if not, the shell variable address@hidden is set to @samp{no}. address@hidden defmac + @defmac AC_C_BACKSLASH_A @acindex{HAVE_C_BACKSLASH_A} Define @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands @@ -14268,11 +14311,6 @@ @code{AC_PREFIX_PROGRAM} @end defmac address@hidden AC_PROG_CC_STDC address@hidden -This macro has been integrated into @code{AC_PROG_CC}. address@hidden defmac - @defmac AC_PROGRAMS_CHECK @acindex{PROGRAMS_CHECK} @code{AC_CHECK_PROGS} Index: lib/autoconf/c.m4 =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v retrieving revision 1.191 diff -u -r1.191 c.m4 --- lib/autoconf/c.m4 2 Dec 2004 20:09:03 -0000 1.191 +++ lib/autoconf/c.m4 29 Dec 2004 17:06:10 -0000 @@ -485,7 +485,7 @@ _AC_LANG_COMPILER_GNU GCC=`test $ac_compiler_gnu = yes && echo yes` _AC_PROG_CC_G -_AC_PROG_CC_STDC +_AC_PROG_CC_C89 # Some people use a C++ compiler to compile C. Since we use `exit', # in C++ we need to declare it. In case someone uses the same compiler # for both compiling C and C++ we need to have the C++ compiler decide @@ -810,17 +810,17 @@ # 4b. C compiler characteristics. # # -------------------------------- # -# _AC_PROG_CC_STDC -# ---------------- -# If the C compiler in not in ANSI C mode by default, try to add an -# option to output variable @code{CC} to make it so. This macro tries -# various options that select ANSI C on some system or another. It -# considers the compiler to be in ANSI C mode if it handles function -# prototypes correctly. -AC_DEFUN([_AC_PROG_CC_STDC], -[AC_MSG_CHECKING([for $CC option to accept ANSI C]) -AC_CACHE_VAL(ac_cv_prog_cc_stdc, -[ac_cv_prog_cc_stdc=no +# _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) +# ---------------------------------------------------------------- +# If the C compiler in not in ANSI C89 (ISO C90) mode by default, try +# to add an option to output variable @code{CC} to make it so. This +# macro tries various options that select ANSI C89 on some system or +# another. It considers the compiler to be in ANSI C89 mode if it +# handles function prototypes correctly. +AC_DEFUN([_AC_PROG_CC_C89], +[AC_MSG_CHECKING([for $CC option to accept ANSI C89 C]) +AC_CACHE_VAL(ac_cv_prog_cc_c89, +[ac_cv_prog_cc_c89=no ac_save_CC=$CC AC_LANG_CONFTEST([AC_LANG_PROGRAM( [[#include @@ -875,26 +875,215 @@ do CC="$ac_save_CC $ac_arg" _AC_COMPILE_IFELSE([], - [ac_cv_prog_cc_stdc=$ac_arg + [ac_cv_prog_cc_c89=$ac_arg break]) done rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC +case "x$ac_cv_prog_cc_c89" in + x|xno) + CC="$ac_save_CC" ;; + *) + CC="$ac_save_CC $ac_cv_prog_cc_c89" ;; +esac ]) -case "x$ac_cv_prog_cc_stdc" in +case "x$ac_cv_prog_cc_c89" in + xno) + AC_MSG_RESULT([unsupported]) + $2 ;; + *) + if test "x$ac_cv_prog_cc_c89" = x; then + AC_MSG_RESULT([none needed]) + else + AC_MSG_RESULT([$ac_cv_prog_cc_c89]) + fi + $1 ;; +esac +])# _AC_PROG_CC_C89 + + +# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) +# ---------------------------------------------------------------- +# If the C compiler in not in ISO C99 C mode by default, try to add an +# option to output variable @code{CC} to make it so. This macro tries +# various options that select ISO C99 C on some system or another. It +# considers the compiler to be in ISO C99 C mode if it handles mixed +# code and declarations, _Bool, inline and restrict. +AC_DEFUN([_AC_PROG_CC_C99], +[AC_MSG_CHECKING([for $CC option to accept ISO C99 C]) +AC_CACHE_VAL(ac_cv_prog_cc_c99, +[ac_cv_prog_cc_c99=no +ac_save_CC=$CC +AC_LANG_CONFTEST([AC_LANG_PROGRAM( +[[#include +#include +#include +#include +#include + +struct incomplete_array +{ + int datasize; + double data[]; +}; + +struct named_init { + int number; + const wchar_t *name; + double average; +}; + +static inline int +test_restrict(const char *restrict text) +{ + // See if C++-style comments work. + // Iterate through items via the restricted pointer. + // Also check for declarations in for loops. + for (unsigned int i = 0; *(text+i) != '\0'; ++i); + return 0; +} + +// Check varargs and va_copy work. +static void +test_varargs(const char *format, ...) +{ + va_list args; + va_start(args, format); + va_list args_copy; + va_copy(args_copy, args); + + const char *str; + int number; + float fnumber; + + while (*format) + { + switch (*format++) + { + case 's': // string + str = va_arg(args_copy, const char *); + break; + case 'd': // int + number = va_arg(args_copy, int); + break; + case 'f': // float + fnumber = (float) va_arg(args_copy, double); + break; + default: + break; + } + } + va_end(args_copy); + va_end(args); +} +]], +[[ + // Check bool and long long datatypes. + _Bool success = false; + long long int bignum = -1234567890LL; + unsigned long long int ubignum = 1234567890uLL; + + // Check restrict. + if (test_restrict("String literal") != 0) + success = true; + char *restrict newvar = "Another string"; + + // Check varargs. + test_varargs("s, d' f .", "string", 65, 34.234); + + // Check incomplete arrays work. + struct incomplete_array *ia = + malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10)); + ia->datasize = 10; + for (int i = 0; i < ia->datasize; ++i) + ia->data[i] = (double) i * 1.234; + + // Check named initialisers. + struct named_init ni = { + .number = 34, + .name = L"Test wide string", + .average = 543.34343, + }; + + ni.number = 58; + + int dynamic_array[ni.number]; + dynamic_array[43] = 543; +]])]) +# Try +# GCC -std=gnu99 -std=c99 -std=iso9899:1999 +# AIX -qlanglvl=extc99 -qlanglvl=stdc99 +# Intel ICC -c99 +# IRIX -c99 +# Solaris -xc99 +# Tru64 -c99 +# with extended modes being tried first. +for ac_arg in "" -std=gnu99 -qlanglvl=extc99 -std=c99 -std=iso9899:1999 -c99 -xc99 -qlanglvl=stdc99 +do + CC="$ac_save_CC $ac_arg" + _AC_COMPILE_IFELSE([], + [ac_cv_prog_cc_c99=$ac_arg +break]) +done +rm -f conftest.$ac_ext conftest.$ac_objext +case "x$ac_cv_prog_cc_c99" in x|xno) - AC_MSG_RESULT([none needed]) ;; + CC="$ac_save_CC" ;; *) - AC_MSG_RESULT([$ac_cv_prog_cc_stdc]) - CC="$CC $ac_cv_prog_cc_stdc" ;; + CC="$ac_save_CC $ac_cv_prog_cc_c99" ;; esac -])# _AC_PROG_CC_STDC +]) +case "x$ac_cv_prog_cc_c99" in + xno) + AC_MSG_RESULT([unsupported]) + $2 ;; + *) + if test "x$ac_cv_prog_cc_c99" = x; then + AC_MSG_RESULT([none needed]) + else + AC_MSG_RESULT([$ac_cv_prog_cc_c99]) + fi + $1 ;; +esac +])# _AC_PROG_CC_C99 + + +# AC_PROG_CC_C89 +# -------------- +AC_DEFUN([AC_PROG_CC_C89], +[ AC_REQUIRE([AC_PROG_CC])dnl + _AC_PROG_CC_C89 +]) + + +# AC_PROG_CC_C99 +# -------------- +AC_DEFUN([AC_PROG_CC_C99], +[ AC_REQUIRE([AC_PROG_CC])dnl + _AC_PROG_CC_C99 +]) # AC_PROG_CC_STDC # --------------- -# Has been merged into AC_PROG_CC. -AU_DEFUN([AC_PROG_CC_STDC], []) +AC_DEFUN([AC_PROG_CC_STDC], +[ AC_REQUIRE([AC_PROG_CC])dnl + _AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99], + [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89], [no])])dnl + AC_MSG_CHECKING([for $CC option to accept ISO Standard C]) + AC_CACHE_VAL([ac_cv_prog_cc_stdc], []) + case "x$ac_cv_prog_cc_stdc" in + xno) + AC_MSG_RESULT([unsupported]) + ;; + *) + if test "x$ac_cv_prog_cc_stdc" = x; then + AC_MSG_RESULT([none needed]) + else + AC_MSG_RESULT([$ac_cv_prog_cc_stdc]) + fi + ;; + esac +]) # AC_C_BACKSLASH_A @@ -1246,7 +1435,7 @@ AC_DEFUN([AC_C_PROTOTYPES], [AC_REQUIRE([AC_PROG_CC])dnl AC_MSG_CHECKING([for function prototypes]) -if test "$ac_cv_prog_cc_stdc" != no; then +if test "$ac_cv_prog_cc_c89" != no; then AC_MSG_RESULT([yes]) AC_DEFINE(PROTOTYPES, 1, [Define to 1 if the C compiler supports function prototypes.])