Update gnulib to current upstream master
[deliverable/binutils-gdb.git] / gdb / gnulib / import / m4 / flexmember.m4
CommitLineData
7a6dbc2f 1# serial 5
49e4877c
PA
2# Check for flexible array member support.
3
7a6dbc2f 4# Copyright (C) 2006, 2009-2018 Free Software Foundation, Inc.
49e4877c
PA
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
11AC_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>
7a6dbc2f
SDJ
20 struct m { struct m *next, **list; char name[]; };
21 struct s { struct s *p; struct m *m; int n; double d[]; };]],
49e4877c
PA
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);
7a6dbc2f
SDJ
27 p->p = p;
28 p->m = NULL;
49e4877c
PA
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; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
38 can be used with pre-C99 compilers.
39 When computing the size of such an object, don't use 'sizeof (struct s)'
40 as it overestimates the size. Use 'offsetof (struct s, d)' instead.
41 Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
42 MSVC and with C++ compilers.])
43 else
44 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])
45 fi
46])
This page took 0.178577 seconds and 4 git commands to generate.