Blame m4/flexmember.m4

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