Add 'restrict' module.
[gnulib.git] / m4 / restrict.m4
1 #serial 1002
2 # This macro can be removed once we can rely on Autoconf 2.57a or later,
3 # since we can then use its AC_C_RESTRICT.
4
5 # gl_C_RESTRICT
6 # --------------
7 # Determine whether the C/C++ compiler supports the "restrict" keyword
8 # introduced in ANSI C99, or an equivalent.  Do nothing if the compiler
9 # accepts it.  Otherwise, if the compiler supports an equivalent,
10 # define "restrict" to be that.  Here are some variants:
11 # - GCC supports both __restrict and __restrict__
12 # - older DEC Alpha C compilers support only __restrict
13 # - _Restrict is the only spelling accepted by Sun WorkShop 6 update 2 C
14 # Otherwise, define "restrict" to be empty.
15 AC_DEFUN([gl_C_RESTRICT],
16 [AC_CACHE_CHECK([for C/C++ restrict keyword], gl_cv_c_restrict,
17   [gl_cv_c_restrict=no
18    # Try the official restrict keyword, then gcc's __restrict, and
19    # the less common variants.
20    for ac_kw in restrict __restrict __restrict__ _Restrict; do
21      AC_COMPILE_IFELSE([AC_LANG_SOURCE(
22       [float * $ac_kw x;])],
23       [gl_cv_c_restrict=$ac_kw; break])
24    done
25   ])
26  case $gl_cv_c_restrict in
27    restrict) ;;
28    no) AC_DEFINE(restrict,,
29         [Define to equivalent of C99 restrict keyword, or to nothing if this
30         is not supported.  Do not define if restrict is supported directly.]) ;;
31    *)  AC_DEFINE_UNQUOTED(restrict, $gl_cv_c_restrict) ;;
32  esac
33 ])