[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AC_C_RESTRICT and C/C++
From: |
Paul Eggert |
Subject: |
Re: AC_C_RESTRICT and C/C++ |
Date: |
Mon, 22 Oct 2007 14:30:27 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Eric Blake-1 <address@hidden> writes:
> Then how about this autoconf patch?
Thanks, I had written up almost exactly the same patch before reading
your email, down to the cleaning up of the AC_DEFINEs. I installed
the union of the two patches:
diff --git a/ChangeLog b/ChangeLog
index 6827771..0044b63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-22 Paul Eggert <address@hidden>
+ and Eric Blake <address@hidden>
+
+ * lib/autoconf/c.m4 (AC_C_RESTRICT): Work around Sun C++ compatibility
+ problem reported by Bruno Haible in
+ <http://lists.gnu.org/archive/html/bug-autoconf/2007-10/msg00027.html>.
+
2007-10-22 Eric Blake <address@hidden>
* doc/autoconf.texi (Particular Types): Mention bug in HP-UX 11.00
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 7e2d76e..b67de57 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1658,28 +1658,38 @@ AN_IDENTIFIER([restrict], [AC_C_RESTRICT])
AC_DEFUN([AC_C_RESTRICT],
[AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
[ac_cv_c_restrict=no
- # Try the official restrict keyword, then gcc's __restrict, and
- # the less common variants.
+ # The order here caters to the fact that C++ does not require restrict.
for ac_kw in __restrict __restrict__ _Restrict restrict; do
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[typedef int * int_ptr;
- int foo (int_ptr $ac_kw ip) {
- return ip[0];
+ int foo (int_ptr $ac_kw ip) {
+ return ip[0];
}]],
[[int s[1];
- int * $ac_kw t = s;
- t[0] = 0;
- return foo(t)]])],
+ int * $ac_kw t = s;
+ t[0] = 0;
+ return foo(t)]])],
[ac_cv_c_restrict=$ac_kw])
test "$ac_cv_c_restrict" != no && break
done
])
+ AH_VERBATIM([restrict],
+[/* Define to the equivalent of the C99 'restrict' keyword, or to
+ nothing if this is not supported. Do not define if restrict is
+ supported directly. */
+#undef restrict
+/* Work around a bug in Sun C++: it does not support _Restrict, even
+ though the corresponding Sun C compiler does, which causes
+ "#define restrict _Restrict" in the previous line. Perhaps some future
+ version of Sun C++ will work with _Restrict; if so, it'll probably
+ define __RESTRICT, just as Sun C does. */
+#if defined __SUNPRO_CC && !defined __RESTRICT
+# define _Restrict
+#endif])
case $ac_cv_c_restrict in
restrict) ;;
- no) AC_DEFINE(restrict,,
- [Define to equivalent of C99 restrict keyword, or to nothing if this
- is not supported. Do not define if restrict is supported directly.]) ;;
- *) AC_DEFINE_UNQUOTED(restrict, $ac_cv_c_restrict) ;;
+ no) AC_DEFINE([restrict], []) ;;
+ *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
esac
])# AC_C_RESTRICT