]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* NEWS: The C99 check now tests for vararg macros and 64-bit
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 24 Aug 2006 18:08:16 +0000 (18:08 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 24 Aug 2006 18:08:16 +0000 (18:08 +0000)
preprocessor ints.
* doc/autoconf.texi (C Compiler): Document // comments, va_copy.
* lib/autoconf/c.m4 (_AC_PROG_CC_C99): Test varargs macros and
64-bit preprocessor ints.  Check for static initialization of
long long.  Remove unnecessary casts.

ChangeLog
NEWS
doc/autoconf.texi
lib/autoconf/c.m4

index d5735eb577b87159d5344339dacace23e4ec6985..cf78babe4261817bae8b234ece67b9036226b57b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-08-24  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * NEWS: The C99 check now tests for vararg macros and 64-bit
+       preprocessor ints.
+       * doc/autoconf.texi (C Compiler): Document // comments, va_copy.
+       * lib/autoconf/c.m4 (_AC_PROG_CC_C99): Test varargs macros and
+       64-bit preprocessor ints.  Check for static initialization of
+       long long.  Remove unnecessary casts.
+
 2006-08-24  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * doc/autoconf.texi (Particular Programs): Mention that
diff --git a/NEWS b/NEWS
index 711e9a90d7864f16e6c070ce377e3cb53f2ff98d..f0fece537b2f464351138643ec63852ff8a40cc3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@
 ** GNU M4 1.4.5 or later is now recommended.  At least one "make check"
   test fails with earlier versions of M4.
 
+** The check for C99 now tests for varargs macros, as documented.
+  It also tests that the preprocessor supports 64-bit integers.
+
 ** Autoconf now uses constructs like "#ifdef HAVE_STDLIB_H" rather than
   "#if HAVE_STDLIB_H", so that it now works with "gcc -Wundef -Werror".
 
index f8e764866da1b2edb5ec964aef681b8df81c8b3f..a105f030b7cc8c479bbd7b4a11e91e1c73b2183f 100644 (file)
@@ -6433,10 +6433,10 @@ If the C compiler is not in 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 C99 on some system or another.  It
 considers the compiler to be in C99 mode if it handles @code{_Bool},
-flexible arrays, @code{inline}, @code{long long int}, mixed code and
-declarations, named initialization of structs, @code{restrict}, varargs
-macros, variable declarations in @code{for} loops and variable length
-arrays.
+@code{//} comments, flexible array members, @code{inline}, @code{long
+long int}, mixed code and declarations, named initialization of structs,
+@code{restrict}, @code{va_copy}, 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 C99; if not, the shell variable
index 4f65475cea7d4cdaa118326583fb36fbd858428d..9334f21c4434d57042631a28c44ad6a5d324cb84 100644 (file)
@@ -1109,8 +1109,11 @@ AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
 # 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.
+# considers the compiler to be in ISO C99 mode if it handles _Bool,
+# // comments, flexible array members, inline, long long int, mixed
+# code and declarations, named initialization of structs, restrict,
+# va_copy, varargs macros, variable declarations in for loops and
+# variable length arrays.
 AC_DEFUN([_AC_PROG_CC_C99],
 [_AC_C_STD_TRY([c99],
 [[#include <stdarg.h>
@@ -1119,6 +1122,35 @@ AC_DEFUN([_AC_PROG_CC_C99],
 #include <wchar.h>
 #include <stdio.h>
 
+// Check varargs macros.  These examples are taken from C99 6.10.3.5.
+#define debug(...) fprintf (stderr, __VA_ARGS__)
+#define showlist(...) puts (#__VA_ARGS__)
+#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
+static void
+test_varargs_macros (void)
+{
+  int x = 1234;
+  int y = 5678;
+  debug ("Flag");
+  debug ("X = %d\n", x);
+  showlist (The first, second, and third items.);
+  report (x>y, "x is %d but y is %d", x, y);
+}
+
+// Check long long types.
+#define BIG64 18446744073709551615ull
+#define BIG32 4294967295ul
+#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
+#if !BIG_OK
+  your preprocessor is broken;
+#endif
+#if BIG_OK
+#else
+  your preprocessor is broken;
+#endif
+static long long int bignum = -9223372036854775807LL;
+static unsigned long long int ubignum = BIG64;
+
 struct incomplete_array
 {
   int datasize;
@@ -1134,7 +1166,7 @@ struct named_init {
 typedef const char *ccp;
 
 static inline int
-test_restrict(ccp restrict text)
+test_restrict (ccp restrict text)
 {
   // See if C++-style comments work.
   // Iterate through items via the restricted pointer.
@@ -1144,14 +1176,14 @@ test_restrict(ccp restrict text)
   return 0;
 }
 
-// Check varargs and va_copy work.
+// Check varargs and va_copy.
 static void
-test_varargs(const char *format, ...)
+test_varargs (const char *format, ...)
 {
   va_list args;
-  va_start(args, format);
+  va_start (args, format);
   va_list args_copy;
-  va_copy(args_copy, args);
+  va_copy (args_copy, args);
 
   const char *str;
   int number;
@@ -1162,44 +1194,43 @@ test_varargs(const char *format, ...)
       switch (*format++)
        {
        case 's': // string
-         str = va_arg(args_copy, const char *);
+         str = va_arg (args_copy, const char *);
          break;
        case 'd': // int
-         number = va_arg(args_copy, int);
+         number = va_arg (args_copy, int);
          break;
        case 'f': // float
-         fnumber = (float) va_arg(args_copy, double);
+         fnumber = va_arg (args_copy, double);
          break;
        default:
          break;
        }
     }
-  va_end(args_copy);
-  va_end(args);
+  va_end (args_copy);
+  va_end (args);
 }
 ]],
 [[
-  // Check bool and long long datatypes.
+  // Check bool.
   _Bool success = false;
-  long long int bignum = -1234567890LL;
-  unsigned long long int ubignum = 1234567890uLL;
 
   // Check restrict.
-  if (test_restrict("String literal") != 0)
+  if (test_restrict ("String literal") == 0)
     success = true;
   char *restrict newvar = "Another string";
 
   // Check varargs.
-  test_varargs("s, d' f .", "string", 65, 34.234);
+  test_varargs ("s, d' f .", "string", 65, 34.234);
+  test_varargs_macros ();
 
-  // Check incomplete arrays work.
+  // Check flexible array members.
   struct incomplete_array *ia =
-    malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
+    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;
+    ia->data[i] = i * 1.234;
 
-  // Check named initialisers.
+  // Check named initializers.
   struct named_init ni = {
     .number = 34,
     .name = L"Test wide string",
@@ -1209,10 +1240,11 @@ test_varargs(const char *format, ...)
   ni.number = 58;
 
   int dynamic_array[ni.number];
-  dynamic_array[43] = 543;
+  dynamic_array[ni.number - 1] = 543;
 
   // work around unused variable warnings
-  return  bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
+  return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
+         || dynamic_array[ni.number - 1] != 543);
 ]],
 dnl Try
 dnl GCC                -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)