diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2007-03-22 21:23:21 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2007-03-22 21:23:21 +0000 |
commit | cbf5993c43f49281173f185863577d86bfac6eae (patch) | |
tree | 90737c96cf15b97273a2bdc5950b3cf09f1d94ca /m4/flexmember.m4 | |
download | coreutils-tarball-cbf5993c43f49281173f185863577d86bfac6eae.tar.gz |
coreutils-6.9coreutils-6.9
Diffstat (limited to 'm4/flexmember.m4')
-rw-r--r-- | m4/flexmember.m4 | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/m4/flexmember.m4 b/m4/flexmember.m4 new file mode 100644 index 0000000..eb5f2b1 --- /dev/null +++ b/m4/flexmember.m4 @@ -0,0 +1,41 @@ +# serial 1 +# Check for flexible array member support. + +# Copyright (C) 2006 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Written by Paul Eggert. + +AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER], +[ + AC_CACHE_CHECK([for flexible array member], + ac_cv_c_flexmember, + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include <stdlib.h> + #include <stdio.h> + #include <stddef.h> + struct s { int n; double d[]; };]], + [[int m = getchar (); + struct s *p = malloc (offsetof (struct s, d) + + m * sizeof (double)); + p->d[0] = 0.0; + return p->d != (double *) NULL;]])], + [ac_cv_c_flexmember=yes], + [ac_cv_c_flexmember=no])]) + if test $ac_cv_c_flexmember = yes; then + AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], + [Define to nothing if C supports flexible array members, and to + 1 if it does not. That way, with a declaration like `struct s + { int n; double d@<:@FLEXIBLE_ARRAY_MEMBER@:>@; };', the struct hack + can be used with pre-C99 compilers. + When computing the size of such an object, don't use 'sizeof (struct s)' + as it overestimates the size. Use 'offsetof (struct s, d)' instead. + Don't use 'offsetof (struct s, d@<:@0@:>@)', as this doesn't work with + MSVC and with C++ compilers.]) + else + AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], 1) + fi +]) |