Home | History | Annotate | Line # | Download | only in m4
      1      1.1  christos # serial 5
      2      1.1  christos # Check for flexible array member support.
      3      1.1  christos 
      4  1.1.1.2  christos # Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
      5      1.1  christos # This file is free software; the Free Software Foundation
      6      1.1  christos # gives unlimited permission to copy and/or distribute it,
      7      1.1  christos # with or without modifications, as long as this notice is preserved.
      8      1.1  christos 
      9      1.1  christos # Written by Paul Eggert.
     10      1.1  christos 
     11      1.1  christos AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER],
     12      1.1  christos [
     13      1.1  christos   AC_CACHE_CHECK([for flexible array member],
     14      1.1  christos     ac_cv_c_flexmember,
     15      1.1  christos     [AC_COMPILE_IFELSE(
     16      1.1  christos        [AC_LANG_PROGRAM(
     17      1.1  christos           [[#include <stdlib.h>
     18      1.1  christos             #include <stdio.h>
     19      1.1  christos             #include <stddef.h>
     20      1.1  christos             struct m { struct m *next, **list; char name[]; };
     21      1.1  christos             struct s { struct s *p; struct m *m; int n; double d[]; };]],
     22      1.1  christos           [[int m = getchar ();
     23      1.1  christos             size_t nbytes = offsetof (struct s, d) + m * sizeof (double);
     24      1.1  christos             nbytes += sizeof (struct s) - 1;
     25      1.1  christos             nbytes -= nbytes % sizeof (struct s);
     26      1.1  christos             struct s *p = malloc (nbytes);
     27      1.1  christos             p->p = p;
     28      1.1  christos             p->m = NULL;
     29      1.1  christos             p->d[0] = 0.0;
     30      1.1  christos             return p->d != (double *) NULL;]])],
     31      1.1  christos        [ac_cv_c_flexmember=yes],
     32      1.1  christos        [ac_cv_c_flexmember=no])])
     33      1.1  christos   if test $ac_cv_c_flexmember = yes; then
     34      1.1  christos     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [],
     35      1.1  christos       [Define to nothing if C supports flexible array members, and to
     36      1.1  christos        1 if it does not.  That way, with a declaration like 'struct s
     37      1.1  christos        { int n; short d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack
     38      1.1  christos        can be used with pre-C99 compilers.
     39      1.1  christos        Use 'FLEXSIZEOF (struct s, d, N * sizeof (short))' to calculate
     40      1.1  christos        the size in bytes of such a struct containing an N-element array.])
     41      1.1  christos   else
     42      1.1  christos     AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1])
     43      1.1  christos   fi
     44      1.1  christos ])
     45