2017-03-19 20:07:03 +00:00
|
|
|
# serial 5
|
2016-09-20 15:30:17 +00:00
|
|
|
# Check for flexible array member support.
|
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
# Copyright (C) 2006, 2009-2024 Free Software Foundation, Inc.
|
2016-09-20 15:30:17 +00:00
|
|
|
# This file is free software; the Free Software Foundation
|
|
|
|
# gives unlimited permission to copy and/or distribute it,
|
|
|
|
# with or without modifications, as long as this notice is preserved.
|
|
|
|
|
|
|
|
# Written by Paul Eggert.
|
|
|
|
|
|
|
|
AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
|
|
|
|
[
|
|
|
|
AC_CACHE_CHECK([for flexible array member],
|
|
|
|
ac_cv_c_flexmember,
|
|
|
|
[AC_COMPILE_IFELSE(
|
|
|
|
[AC_LANG_PROGRAM(
|
|
|
|
[[#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
2017-03-19 20:07:03 +00:00
|
|
|
struct m { struct m *next, **list; char name[]; };
|
|
|
|
struct s { struct s *p; struct m *m; int n; double d[]; };]],
|
2016-09-20 15:30:17 +00:00
|
|
|
[[int m = getchar ();
|
|
|
|
size_t nbytes = offsetof (struct s, d) + m * sizeof (double);
|
|
|
|
nbytes += sizeof (struct s) - 1;
|
|
|
|
nbytes -= nbytes % sizeof (struct s);
|
|
|
|
struct s *p = malloc (nbytes);
|
2017-03-19 20:07:03 +00:00
|
|
|
p->p = p;
|
|
|
|
p->m = NULL;
|
2016-09-20 15:30:17 +00:00
|
|
|
p->d[0] = 0.0;
|
|
|
|
return p->d != (double *) NULL;]])],
|
|
|
|
[ac_cv_c_flexmember=yes],
|
|
|
|
[ac_cv_c_flexmember=no])])
|
|
|
|
if test $ac_cv_c_flexmember = yes; then
|
|
|
|
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
|
|
|
|
[Define to nothing if C supports flexible array members, and to
|
|
|
|
1 if it does not. That way, with a declaration like 'struct s
|
2019-05-29 23:33:51 +00:00
|
|
|
{ int n; short d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
|
2016-09-20 15:30:17 +00:00
|
|
|
can be used with pre-C99 compilers.
|
2019-05-29 23:33:51 +00:00
|
|
|
Use 'FLEXSIZEOF (struct s, d, N * sizeof (short))' to calculate
|
|
|
|
the size in bytes of such a struct containing an N-element array.])
|
2016-09-20 15:30:17 +00:00
|
|
|
else
|
|
|
|
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])
|
|
|
|
fi
|
|
|
|
])
|