bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

borrow AC_C_RESTRICT from autoconf


From: Bruno Haible
Subject: borrow AC_C_RESTRICT from autoconf
Date: Sat, 27 Oct 2007 03:39:49 +0200
User-agent: KMail/1.5.4

Hi,

The autoconf macro for 'restrict', as modified in
  <http://lists.gnu.org/archive/html/bug-autoconf/2007-10/msg00032.html>
fixes problems with mixed use of C and C++. gettext needs it, maybe others
too. I'm therefore adding an override to gnulib. We need can remove it once
autoconf 2.62 can be assumed.

I verified that it fixes gettext's problem with Sun C++.


2007-10-26  Bruno Haible  <address@hidden>

        * m4/gnulib-common.m4 (AC_C_RESTRICT): New overriding definition,
        borrowed from autoconf.

--- m4/gnulib-common.m4.orig    2007-10-27 03:36:08.000000000 +0200
+++ m4/gnulib-common.m4 2007-10-26 02:25:09.000000000 +0200
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 2
+# gnulib-common.m4 serial 3
 dnl Copyright (C) 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -20,3 +20,46 @@
     [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake
      MKDIR_P='$(mkdir_p)'
      AC_SUBST([MKDIR_P])])])
+
+# AC_C_RESTRICT
+# This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61,
+# so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++
+# works.
+# This definition can be removed once autoconf >= 2.62 can be assumed.
+AC_DEFUN([AC_C_RESTRICT],
+[AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
+  [ac_cv_c_restrict=no
+   # 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 s[1];
+       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], []) ;;
+   *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
+ esac
+])





reply via email to

[Prev in Thread] Current Thread [Next in Thread]