2 # Check for flexible array member support.
4 # Copyright (C) 2006, 2009-2018 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; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
38 can be used with pre-C99 compilers.
39 When computing the size of such an object, don't use 'sizeof (struct s)'
40 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
41 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
42 MSVC and with C++ compilers.])
44 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])