2 # Check for flexible array member support.
4 # Copyright (C) 2006, 2009-2017 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 s { int n; double d[]; };]],
22 size_t nbytes = offsetof (struct s, d) + m * sizeof (double);
23 nbytes += sizeof (struct s) - 1;
24 nbytes -= nbytes % sizeof (struct s);
25 struct s *p = malloc (nbytes);
27 return p->d != (double *) NULL;]])],
28 [ac_cv_c_flexmember=yes],
29 [ac_cv_c_flexmember=no])])
30 if test $ac_cv_c_flexmember = yes; then
31 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
32 [Define to nothing if C supports flexible array members, and to
33 1 if it does not. That way, with a declaration like 'struct s
34 { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
35 can be used with pre-C99 compilers.
36 When computing the size of such an object, don't use 'sizeof (struct s)'
37 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
38 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
39 MSVC and with C++ compilers.])
41 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])