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