-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexible.m4
34 lines (34 loc) · 1.36 KB
/
flexible.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# AC_C_FLEXIBLE_ARRAY_MEMBER
# --------------------------
# Check whether the C compiler supports flexible array members.
AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
[
AC_CACHE_CHECK([for flexible array members],
ac_cv_c_flexmember,
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
struct s { int n; double d[]; };]],
[[int m = getchar ();
struct s *p = malloc (offsetof (struct s, d)
+ m * sizeof (double));
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
{ int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
can be used with pre-C99 compilers.
When computing the size of such an object, don't use 'sizeof (struct s)'
as it overestimates the size. Use 'offsetof (struct s, d)' instead.
Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
MSVC and with C++ compilers.])
else
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1)
fi
])