Blame m4/flexmember.m4

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