| 1 |
# flexmember.m4 |
| 2 |
# serial 5 |
| 3 |
dnl Copyright (C) 2006, 2009-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
# Check for flexible array member support. |
| 10 |
|
| 11 |
# Written by Paul Eggert. |
| 12 |
|
| 13 |
AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER], |
| 14 |
[ |
| 15 |
AC_CACHE_CHECK([for flexible array member], |
| 16 |
ac_cv_c_flexmember, |
| 17 |
[AC_COMPILE_IFELSE( |
| 18 |
[AC_LANG_PROGRAM( |
| 19 |
[[#include <stdlib.h> |
| 20 |
#include <stdio.h> |
| 21 |
#include <stddef.h> |
| 22 |
struct m { struct m *next, **list; char name[]; }; |
| 23 |
struct s { struct s *p; struct m *m; int n; double d[]; };]], |
| 24 |
[[int m = getchar (); |
| 25 |
size_t nbytes = offsetof (struct s, d) + m * sizeof (double); |
| 26 |
nbytes += sizeof (struct s) - 1; |
| 27 |
nbytes -= nbytes % sizeof (struct s); |
| 28 |
struct s *p = malloc (nbytes); |
| 29 |
p->p = p; |
| 30 |
p->m = NULL; |
| 31 |
p->d[0] = 0.0; |
| 32 |
return p->d != (double *) NULL;]])], |
| 33 |
[ac_cv_c_flexmember=yes], |
| 34 |
[ac_cv_c_flexmember=no])]) |
| 35 |
if test $ac_cv_c_flexmember = yes; then |
| 36 |
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], |
| 37 |
[Define to nothing if C supports flexible array members, and to |
| 38 |
1 if it does not. That way, with a declaration like 'struct s |
| 39 |
{ int n; short d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack |
| 40 |
can be used with pre-C99 compilers. |
| 41 |
Use 'FLEXSIZEOF (struct s, d, N * sizeof (short))' to calculate |
| 42 |
the size in bytes of such a struct containing an N-element array.]) |
| 43 |
else |
| 44 |
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1]) |
| 45 |
fi |
| 46 |
]) |