[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AC_PROG_CC_C99
From: |
Paul Eggert |
Subject: |
Re: AC_PROG_CC_C99 |
Date: |
Sun, 02 Jan 2005 23:35:42 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Thanks for your patch. It caused "make check" to fail, and there
were some minor glitches in the comments, but it otherwise looks
good to me. I installed this minor variant on what you sent in:
2005-01-02 Paul Eggert <address@hidden>
Patch from Roger Leigh (with some minor changes) as follows:
* NEWS: New macros AC_PROG_CC_C89, AC_PROG_CC_C99.
Resurrect AC_PROG_CC_STDC.
* doc/autoconf.texi (C Compiler): Add AC_PROG_CC_STDC,
AC_PROG_CC_C89, AC_PROG_CC_C99.
(Obsolete Macros): Remove AC_PROG_CC_STDC; it's no longer obsolete.
* lib/autoconf/c.m4 (_AC_PROG_CC_C89, _AC_PROG_CC_C99, AC_PROG_CC_C89,
AC_PROG_CC_C99): New macros.
(AC_PROG_CC_STDC): Use them.
(_AC_PROG_CC_STDC): Remove.
(AC_C_PROTOTYPES): Use ac_cv_prog_cc_c89, not ac_cv_prog_cc_stdc.
* THANKS: Add Roger Leigh.
Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.333
diff -p -u -r1.333 NEWS
--- NEWS 17 Dec 2004 16:17:18 -0000 1.333
+++ NEWS 3 Jan 2005 07:32:00 -0000
@@ -1,5 +1,16 @@
* Major changes in Autoconf 2.59c
+** AC_PROG_CC_C89, AC_PROG_CC_C99
+ New macros for ISO C99 support. AC_PROG_CC_C89 and AC_PROG_CC_C99
+ check for ANSI C89 and ISO C99 support respectively.
+
+** 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.
@@ -1197,7 +1208,7 @@ Various bug fixes.
-----
Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
-2003, 2004 Free Software Foundation, Inc.
+2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Autoconf.
Index: THANKS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/THANKS,v
retrieving revision 1.126
diff -p -u -r1.126 THANKS
--- THANKS 2 Jan 2005 17:15:40 -0000 1.126
+++ THANKS 3 Jan 2005 07:32:00 -0000
@@ -174,6 +174,7 @@ Richard Stallman address@hidden
Robert Lipe address@hidden
Robert S. Maier address@hidden
Roberto Bagnara address@hidden
+Roger Leigh address@hidden
Roland McGrath address@hidden
Ruediger Kuhlmann address@hidden
Russ Allbery address@hidden
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.858
diff -p -u -r1.858 autoconf.texi
--- doc/autoconf.texi 1 Jan 2005 08:12:12 -0000 1.858
+++ doc/autoconf.texi 3 Jan 2005 07:32:01 -0000
@@ -181,7 +181,7 @@ a package for creating scripts to config
templates and an M4 macro package.
Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
@@ -5597,15 +5597,15 @@ this:
AC_PROG_CC(cl egcs gcc cc)
@end example
-If the C compiler is not in @acronym{ANSI} C mode by default, try to add an
+If the C compiler is not in @acronym{ANSI} 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} C on some system or another. It
-considers the compiler to be in @acronym{ANSI} C mode if it handles function
+considers the compiler to be in @acronym{ANSI} 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} 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 @@ features. To check for characteristics
@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 ISO Standard C (currently ISO
+C99), try to add an option to output variable @code{CC} to make it so.
+If the compiler does not support ISO C99, fall back to supporting
address@hidden C89 (ISO C90).
+
+After calling this macro you can check whether the C compiler has been
+set to accept 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 (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; 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 ISO C99 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 on some system or another. It
+considers the compiler to be in ISO C99 mode if it handles @code{_Bool},
+flexible arrays, @code{inline}, @code{long long}, mixed code and
+declarations, named initialization of structs, @code{restrict}, varargs
+macros, variable declarations in @code{for} loops and variable length
+arrays.
+
+After calling this macro you can check whether the C compiler has been
+set to accept ISO C99; 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 @@ AC_CONFIG_COMMANDS([default], [[echo "Sq
@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 -p -u -r1.191 c.m4
--- lib/autoconf/c.m4 2 Dec 2004 20:09:03 -0000 1.191
+++ lib/autoconf/c.m4 3 Jan 2005 07:32:01 -0000
@@ -1,6 +1,6 @@
# This file is part of Autoconf. -*- Autoconf -*-
# Programming languages support.
-# Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -485,7 +485,7 @@ m4_expand_once([_AC_COMPILER_OBJEXT])[]d
_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 @@ fi
# 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 is not in ANSI C89 (ISO C90) mode by default, try
+# to add an option to output variable 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])
+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 <stdarg.h>
@@ -875,26 +875,219 @@ for ac_arg in "" -qlanglvl=extc89 -qlang
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
+# Because of `break', _AC_COMPILE_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+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 is not in ISO C99 mode by default, try to add an
+# option to output variable CC to make it so. This macro tries
+# various options that select ISO C99 on some system or another. It
+# considers the compiler to be in ISO C99 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])
+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 <stdarg.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <stdio.h>
+
+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)
+ continue;
+ 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 (unused restrictive modes: -std=c99
-std=iso9899:1999)
+# AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
+# Intel ICC -c99
+# IRIX -c99
+# Solaris (unused because it causes the compiler to assume C99 semantics
for
+# library functions, and this is invalid before Solaris 10: -xc99)
+# Tru64 -c99
+# with extended modes being tried first.
+for ac_arg in "" -std=gnu99 -c99 -qlanglvl=extc99
+do
+ CC="$ac_save_CC $ac_arg"
+ _AC_COMPILE_IFELSE([],
+ [ac_cv_prog_cc_c99=$ac_arg
+break])
+done
+# Because of `break', _AC_COMPILE_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+case "x$ac_cv_prog_cc_c99" in
x|xno)
- AC_MSG_RESULT([none needed]) ;;
+ CC="$ac_save_CC" ;;
+ *)
+ CC="$ac_save_CC $ac_cv_prog_cc_c99" ;;
+esac
+])
+case "x$ac_cv_prog_cc_c99" in
+ xno)
+ AC_MSG_RESULT([unsupported])
+ $2 ;;
*)
- AC_MSG_RESULT([$ac_cv_prog_cc_stdc])
- CC="$CC $ac_cv_prog_cc_stdc" ;;
+ 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_STDC
+])# _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 +1439,7 @@ fi
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.])
- Re: AC_PROG_CC_C99, Roger Leigh, 2005/01/01
- Re: AC_PROG_CC_C99,
Paul Eggert <=
- Re: AC_PROG_CC_C99, Noah Misch, 2005/01/04
- Re: AC_PROG_CC_C99, Paul Eggert, 2005/01/04
- Re: AC_PROG_CC_C99, Noah Misch, 2005/01/04
- Re: AC_PROG_CC_C99, Roger Leigh, 2005/01/05
- Re: AC_PROG_CC_C99, Noah Misch, 2005/01/09
- Re: AC_PROG_CC_C99, Roger Leigh, 2005/01/12
- Re: AC_PROG_CC_C99, Noah Misch, 2005/01/13
- Re: AC_PROG_CC_C99, Roger Leigh, 2005/01/05