re-mark 1.29b-2 as not yet uploaded (merge madness!)
[debian/tar] / m4 / flexmember.m4
1 # serial 3
2 # Check for flexible array member support.
3
4 # Copyright (C) 2006, 2009-2015 Free Software Foundation, Inc.
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
11 AC_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>
20             struct s { int n; double d[]; };]],
21           [[int m = getchar ();
22             struct s *p = malloc (offsetof (struct s, d)
23                                   + m * sizeof (double));
24             p->d[0] = 0.0;
25             return p->d != (double *) NULL;]])],
26        [ac_cv_c_flexmember=yes],
27        [ac_cv_c_flexmember=no])])
28   if test $ac_cv_c_flexmember = yes; then
29     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
30       [Define to nothing if C supports flexible array members, and to
31        1 if it does not.  That way, with a declaration like 'struct s
32        { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
33        can be used with pre-C99 compilers.
34        When computing the size of such an object, don't use 'sizeof (struct s)'
35        as it overestimates the size.  Use 'offsetof (struct s, d)' instead.
36        Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with
37        MSVC and with C++ compilers.])
38   else
39     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])
40   fi
41 ])