Blame m4/flexmember.m4

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