summaryrefslogtreecommitdiffstats
path: root/gl/m4/vararrays.m4
blob: 9211f69d4d8b9f800af9e31dd29d5319a388d388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# vararrays.m4
# serial 6
dnl Copyright (C) 2001, 2009-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

# Check for variable-length arrays.

# From Paul Eggert

m4_version_prereq([2.70], [], [

# AC_C_VARARRAYS
# --------------
# Check whether the C compiler supports variable-length arrays.
AC_DEFUN([AC_C_VARARRAYS],
[
  AC_CACHE_CHECK([for variable-length arrays],
    ac_cv_c_vararrays,
    [AC_EGREP_CPP([defined],
       [#ifdef __STDC_NO_VLA__
        defined
        #endif
       ],
       [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
       [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM(
             [[/* Test for VLA support.  This test is partly inspired
                  from examples in the C standard.  Use at least two VLA
                  functions to detect the GCC 3.4.3 bug described in:
                  https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
                  */
               #ifdef __STDC_NO_VLA__
                syntax error;
               #else
                 extern int n;
                 int B[100];
                 int fvla (int m, int C[m][m]);

                 int
                 simple (int count, int all[static count])
                 {
                   return all[count - 1];
                 }

                 int
                 fvla (int m, int C[m][m])
                 {
                   typedef int VLA[m][m];
                   VLA x;
                   int D[m];
                   static int (*q)[m] = &B;
                   int (*s)[n] = q;
                   return C && &x[0][0] == &D[0] && &D[0] == s[0];
                 }
               #endif
               ]])],
          [ac_cv_c_vararrays=yes],
          [ac_cv_c_vararrays=no])])])
  if test "$ac_cv_c_vararrays" = yes; then
    dnl This is for compatibility with Autoconf 2.61-2.69.
    AC_DEFINE([HAVE_C_VARARRAYS], 1,
      [Define to 1 if C supports variable-length arrays.])
  elif test "$ac_cv_c_vararrays" = no; then
    AC_DEFINE([__STDC_NO_VLA__], 1,
      [Define to 1 if C does not support variable-length arrays, and
       if the compiler does not already define this.])
  fi
])

])