[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Variadic macro support
From: |
Paul Eggert |
Subject: |
Re: Variadic macro support |
Date: |
Thu, 24 Aug 2006 11:11:51 -0700 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
nash <address@hidden> writes:
> Does anyone happen to have a check to determine if variadic macros
> with no named args are supported in C99 mode? The following works fine
> under gcc, but flames out with a nasty-gram under AIX's c99 compiler:
>
> #define my_debug_macro(...) some_debug_function(__FILE__, __LINE__,
> __VA_ARGS__)
Ouch, that's a new one on me. That macro conforms to C99, so clearly
it's an AIX c99 bug.
Autoconf is documented to test for this bug and it currently doesn't
test for it. So I installed the following patch. This doesn't solve
your immediate problem but should help long-term.
Have you tried 'c99 -qlanglvl=extc99'? If that doesn't work, perhaps
some other compiler or option combination does work? If so, please
let us know, so we can fix Autoconf to try that combination. Either
way, you should file a bug report with IBM.
Thanks for reporting this.
2006-08-24 Paul Eggert <address@hidden>
* 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.
Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.393
diff -p -u -r1.393 NEWS
--- NEWS 15 Aug 2006 16:24:42 -0000 1.393
+++ NEWS 24 Aug 2006 18:07:48 -0000
@@ -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: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1071
diff -p -u -r1.1071 autoconf.texi
--- doc/autoconf.texi 24 Aug 2006 16:58:54 -0000 1.1071
+++ doc/autoconf.texi 24 Aug 2006 18:07:49 -0000
@@ -6433,10 +6433,10 @@ If the C compiler is not in C99 mode by
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.
address@hidden//} comments, flexible array members, @code{inline}, @code{long
+long int}, mixed code and declarations, named initialization of structs,
address@hidden, @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: lib/autoconf/c.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v
retrieving revision 1.233
diff -p -u -r1.233 c.m4
--- lib/autoconf/c.m4 22 Aug 2006 20:09:51 -0000 1.233
+++ lib/autoconf/c.m4 24 Aug 2006 18:07:49 -0000
@@ -1109,8 +1109,11 @@ AS_IF([test "x$ac_cv_prog_cc_$1" != xno]
# 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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Variadic macro support,
Paul Eggert <=