Bump to m4 1.4.19
[platform/upstream/m4.git] / m4 / flexmember.m4
1 # serial 5
2 # Check for flexible array member support.
3
4 # Copyright (C) 2006, 2009-2021 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
9 # Written by Paul Eggert.
10
11 AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
12 [
13   AC_CACHE_CHECK([for flexible array member],
14     ac_cv_c_flexmember,
15     [AC_COMPILE_IFELSE(
16        [AC_LANG_PROGRAM(
17           [[#include <stdlib.h>
18             #include <stdio.h>
19             #include <stddef.h>
20             struct m { struct m *next, **list; char name[]; };
21             struct s { struct s *p; struct m *m; int n; double d[]; };]],
22           [[int m = getchar ();
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);
27             p->p = p;
28             p->m = NULL;
29             p->d[0] = 0.0;
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.])
41   else
42     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])
43   fi
44 ])