"Fossies" - the Fresh Open Source Software Archive

Member "gnuastro-0.8/bootstrapped/m4/flexmember.m4" (28 Dec 2018, 1835 Bytes) of package /linux/privat/gnuastro-0.8.tar.lz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "flexmember.m4": 0.5_vs_0.6.

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