1*4b169a6bSchristos# Check for variable-length arrays. 2*4b169a6bSchristos 3*4b169a6bSchristos# serial 6 4*4b169a6bSchristos 5*4b169a6bSchristos# From Paul Eggert 6*4b169a6bSchristos 7*4b169a6bSchristos# Copyright (C) 2001, 2009-2022 Free Software Foundation, Inc. 8*4b169a6bSchristos# This file is free software; the Free Software Foundation 9*4b169a6bSchristos# gives unlimited permission to copy and/or distribute it, 10*4b169a6bSchristos# with or without modifications, as long as this notice is preserved. 11*4b169a6bSchristos 12*4b169a6bSchristosm4_version_prereq([2.70], [], [ 13*4b169a6bSchristos 14*4b169a6bSchristos# AC_C_VARARRAYS 15*4b169a6bSchristos# -------------- 16*4b169a6bSchristos# Check whether the C compiler supports variable-length arrays. 17*4b169a6bSchristosAC_DEFUN([AC_C_VARARRAYS], 18*4b169a6bSchristos[ 19*4b169a6bSchristos AC_CACHE_CHECK([for variable-length arrays], 20*4b169a6bSchristos ac_cv_c_vararrays, 21*4b169a6bSchristos [AC_EGREP_CPP([defined], 22*4b169a6bSchristos [#ifdef __STDC_NO_VLA__ 23*4b169a6bSchristos defined 24*4b169a6bSchristos #endif 25*4b169a6bSchristos ], 26*4b169a6bSchristos [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'], 27*4b169a6bSchristos [AC_COMPILE_IFELSE( 28*4b169a6bSchristos [AC_LANG_PROGRAM( 29*4b169a6bSchristos [[/* Test for VLA support. This test is partly inspired 30*4b169a6bSchristos from examples in the C standard. Use at least two VLA 31*4b169a6bSchristos functions to detect the GCC 3.4.3 bug described in: 32*4b169a6bSchristos https://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html 33*4b169a6bSchristos */ 34*4b169a6bSchristos #ifdef __STDC_NO_VLA__ 35*4b169a6bSchristos syntax error; 36*4b169a6bSchristos #else 37*4b169a6bSchristos extern int n; 38*4b169a6bSchristos int B[100]; 39*4b169a6bSchristos int fvla (int m, int C[m][m]); 40*4b169a6bSchristos 41*4b169a6bSchristos int 42*4b169a6bSchristos simple (int count, int all[static count]) 43*4b169a6bSchristos { 44*4b169a6bSchristos return all[count - 1]; 45*4b169a6bSchristos } 46*4b169a6bSchristos 47*4b169a6bSchristos int 48*4b169a6bSchristos fvla (int m, int C[m][m]) 49*4b169a6bSchristos { 50*4b169a6bSchristos typedef int VLA[m][m]; 51*4b169a6bSchristos VLA x; 52*4b169a6bSchristos int D[m]; 53*4b169a6bSchristos static int (*q)[m] = &B; 54*4b169a6bSchristos int (*s)[n] = q; 55*4b169a6bSchristos return C && &x[0][0] == &D[0] && &D[0] == s[0]; 56*4b169a6bSchristos } 57*4b169a6bSchristos #endif 58*4b169a6bSchristos ]])], 59*4b169a6bSchristos [ac_cv_c_vararrays=yes], 60*4b169a6bSchristos [ac_cv_c_vararrays=no])])]) 61*4b169a6bSchristos if test "$ac_cv_c_vararrays" = yes; then 62*4b169a6bSchristos dnl This is for compatibility with Autoconf 2.61-2.69. 63*4b169a6bSchristos AC_DEFINE([HAVE_C_VARARRAYS], 1, 64*4b169a6bSchristos [Define to 1 if C supports variable-length arrays.]) 65*4b169a6bSchristos elif test "$ac_cv_c_vararrays" = no; then 66*4b169a6bSchristos AC_DEFINE([__STDC_NO_VLA__], 1, 67*4b169a6bSchristos [Define to 1 if C does not support variable-length arrays, and 68*4b169a6bSchristos if the compiler does not already define this.]) 69*4b169a6bSchristos fi 70*4b169a6bSchristos]) 71*4b169a6bSchristos 72*4b169a6bSchristos]) 73