summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h.in9
-rwxr-xr-xconfigure50
-rw-r--r--configure.ac1
-rw-r--r--src/lib/aplwc_internal.h4
4 files changed, 61 insertions, 3 deletions
diff --git a/config.h.in b/config.h.in
index fbdc27b..cd458a5 100644
--- a/config.h.in
+++ b/config.h.in
@@ -9,6 +9,15 @@
/* Defined if the build mode is "release" */
#undef APLWC_BUILD_TYPE_RELEASE
+/* 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. */
+#undef FLEXIBLE_ARRAY_MEMBER
+
/* Name of package */
#undef PACKAGE
diff --git a/configure b/configure
index 4727c37..9ea8331 100755
--- a/configure
+++ b/configure
@@ -4488,6 +4488,55 @@ else
fi
+
+
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for flexible array members" >&5
+printf %s "checking for flexible array members... " >&6; }
+if test ${ac_cv_c_flexmember+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+ #include <stdio.h>
+ #include <stddef.h>
+ struct s { int n; double d[]; };
+int
+main (void)
+{
+int m = getchar ();
+ struct s *p = (struct s *) malloc (offsetof (struct s, d)
+ + m * sizeof (double));
+ p->d[0] = 0.0;
+ m = p->d != (double *) NULL;
+ free (p);
+ return m;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+ ac_cv_c_flexmember=yes
+else case e in #(
+ e) ac_cv_c_flexmember=no ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_flexmember" >&5
+printf "%s\n" "$ac_cv_c_flexmember" >&6; }
+ if test $ac_cv_c_flexmember = yes; then
+
+printf "%s\n" "#define FLEXIBLE_ARRAY_MEMBER /**/" >>confdefs.h
+
+ else
+ printf "%s\n" "#define FLEXIBLE_ARRAY_MEMBER 1" >>confdefs.h
+
+ fi
+
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
@@ -4593,7 +4642,6 @@ else
fi
-
if test -n "$ac_tool_prefix"; then
for ac_prog in ar lib "link -lib"
do
diff --git a/configure.ac b/configure.ac
index 6890ddc..db987c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,6 +7,7 @@ AC_CONFIG_SRCDIR([src/bin/main.c])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
+AC_C_FLEXIBLE_ARRAY_MEMBER
AC_PROG_RANLIB
AM_PROG_AR
diff --git a/src/lib/aplwc_internal.h b/src/lib/aplwc_internal.h
index 328b5de..8c13dfe 100644
--- a/src/lib/aplwc_internal.h
+++ b/src/lib/aplwc_internal.h
@@ -67,7 +67,7 @@ struct aplwc_line {
struct string {
size_t bytes;
size_t chars;
- uint8_t utf8[1];
+ uint8_t utf8[FLEXIBLE_ARRAY_MEMBER];
};
enum token_tag {
@@ -100,7 +100,7 @@ struct token {
struct token_list {
struct string *text;
size_t length;
- struct token tokens[1];
+ struct token tokens[FLEXIBLE_ARRAY_MEMBER];
};
enum value_tag {