1 # Check for variable-length arrays.
7 # Copyright (C) 2001, 2009-2020 Free Software Foundation, Inc.
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
12 m4_version_prereq([2.70], [], [
16 # Check whether the C compiler supports variable-length arrays.
17 AC_DEFUN([AC_C_VARARRAYS],
19 AC_CACHE_CHECK([for variable-length arrays],
21 [AC_EGREP_CPP([defined],
22 [#ifdef __STDC_NO_VLA__
26 [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
29 [[/* Test for VLA support. This test is partly inspired
30 from examples in the C standard. Use at least two VLA
31 functions to detect the GCC 3.4.3 bug described in:
32 https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
34 #ifdef __STDC_NO_VLA__
39 int fvla (int m, int C[m][m]);
42 simple (int count, int all[static count])
44 return all[count - 1];
48 fvla (int m, int C[m][m])
50 typedef int VLA[m][m];
53 static int (*q)[m] = &B;
55 return C && &x[0][0] == &D[0] && &D[0] == s[0];
59 [ac_cv_c_vararrays=yes],
60 [ac_cv_c_vararrays=no])])])
61 if test "$ac_cv_c_vararrays" = yes; then
62 dnl This is for compatibility with Autoconf 2.61-2.69.
63 AC_DEFINE([HAVE_C_VARARRAYS], 1,
64 [Define to 1 if C supports variable-length arrays.])
65 elif test "$ac_cv_c_vararrays" = no; then
66 AC_DEFINE([__STDC_NO_VLA__], 1,
67 [Define to 1 if C does not support variable-length arrays, and
68 if the compiler does not already define this.])