vararrays.m4 2.3 KB

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