|
Packit |
8f70b4 |
# serial 5
|
|
Packit |
8f70b4 |
# Check for flexible array member support.
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
# Copyright (C) 2006, 2009-2018 Free Software Foundation, Inc.
|
|
Packit |
8f70b4 |
# This file is free software; the Free Software Foundation
|
|
Packit |
8f70b4 |
# gives unlimited permission to copy and/or distribute it,
|
|
Packit |
8f70b4 |
# with or without modifications, as long as this notice is preserved.
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
# Written by Paul Eggert.
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
|
|
Packit |
8f70b4 |
[
|
|
Packit |
8f70b4 |
AC_CACHE_CHECK([for flexible array member],
|
|
Packit |
8f70b4 |
ac_cv_c_flexmember,
|
|
Packit |
8f70b4 |
[AC_COMPILE_IFELSE(
|
|
Packit |
8f70b4 |
[AC_LANG_PROGRAM(
|
|
Packit |
8f70b4 |
[[#include <stdlib.h>
|
|
Packit |
8f70b4 |
#include <stdio.h>
|
|
Packit |
8f70b4 |
#include <stddef.h>
|
|
Packit |
8f70b4 |
struct m { struct m *next, **list; char name[]; };
|
|
Packit |
8f70b4 |
struct s { struct s *p; struct m *m; int n; double d[]; };]],
|
|
Packit |
8f70b4 |
[[int m = getchar ();
|
|
Packit |
8f70b4 |
size_t nbytes = offsetof (struct s, d) + m * sizeof (double);
|
|
Packit |
8f70b4 |
nbytes += sizeof (struct s) - 1;
|
|
Packit |
8f70b4 |
nbytes -= nbytes % sizeof (struct s);
|
|
Packit |
8f70b4 |
struct s *p = malloc (nbytes);
|
|
Packit |
8f70b4 |
p->p = p;
|
|
Packit |
8f70b4 |
p->m = NULL;
|
|
Packit |
8f70b4 |
p->d[0] = 0.0;
|
|
Packit |
8f70b4 |
return p->d != (double *) NULL;]])],
|
|
Packit |
8f70b4 |
[ac_cv_c_flexmember=yes],
|
|
Packit |
8f70b4 |
[ac_cv_c_flexmember=no])])
|
|
Packit |
8f70b4 |
if test $ac_cv_c_flexmember = yes; then
|
|
Packit |
8f70b4 |
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
|
|
Packit |
8f70b4 |
[Define to nothing if C supports flexible array members, and to
|
|
Packit |
8f70b4 |
1 if it does not. That way, with a declaration like 'struct s
|
|
Packit |
8f70b4 |
{ int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
|
|
Packit |
8f70b4 |
can be used with pre-C99 compilers.
|
|
Packit |
8f70b4 |
When computing the size of such an object, don't use 'sizeof (struct s)'
|
|
Packit |
8f70b4 |
as it overestimates the size. Use 'offsetof (struct s, d)' instead.
|
|
Packit |
8f70b4 |
Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
|
|
Packit |
8f70b4 |
MSVC and with C++ compilers.])
|
|
Packit |
8f70b4 |
else
|
|
Packit |
8f70b4 |
AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])
|
|
Packit |
8f70b4 |
fi
|
|
Packit |
8f70b4 |
])
|