Blame m4/flexmember.m4

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