2 # Check for flexible array member support.
4 # Copyright (C) 2006, 2009-2020 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.
9 # Written by Paul Eggert.
11 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
13 AC_CACHE_CHECK([for flexible array member],
20 struct m { struct m *next, **list; char name[]; };
21 struct s { struct s *p; struct m *m; int n; double d[]; };]],
23 size_t nbytes = offsetof (struct s, d) + m * sizeof (double);
24 nbytes += sizeof (struct s) - 1;
25 nbytes -= nbytes % sizeof (struct s);
26 struct s *p = malloc (nbytes);
30 return p->d != (double *) NULL;]])],
31 [ac_cv_c_flexmember=yes],
32 [ac_cv_c_flexmember=no])])
33 if test $ac_cv_c_flexmember = yes; then
34 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
35 [Define to nothing if C supports flexible array members, and to
36 1 if it does not. That way, with a declaration like 'struct s
37 { int n; short d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
38 can be used with pre-C99 compilers.
39 Use 'FLEXSIZEOF (struct s, d, N * sizeof (short))' to calculate
40 the size in bytes of such a struct containing an N-element array.])
42 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])