From a127a332ac940b05eb0039fbcdd5434358dfb9a7 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 9 Jan 2022 21:29:00 +0900 Subject: [PATCH] use 0 (configurable) for the C++ size of flexible arrays (fixes #808) --- include/chibi/features.h | 9 +++++++++ include/chibi/sexp.h | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/chibi/features.h b/include/chibi/features.h index a4c22954..e9e85d96 100644 --- a/include/chibi/features.h +++ b/include/chibi/features.h @@ -324,6 +324,15 @@ #define SEXP_MAX_ANALYZE_DEPTH 8192 #endif +/* The size of flexible arrays (empty arrays at the end of a struct */ +/* representing the trailing data), when compiled with C++. Technically */ +/* 0 is an illegal value here, and the C++ idiom is to use 1, but this */ +/* breaks compatibility with C when computing the size of structs, and */ +/* in practice all of the major C++ compilers support 0. */ +#ifndef SEXP_FLEXIBLE_ARRAY_SIZE +#define SEXP_FLEXIBLE_ARRAY_SIZE 0 +#endif + /************************************************************************/ /* DEFAULTS - DO NOT MODIFY ANYTHING BELOW THIS LINE */ /************************************************************************/ diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index f82d588d..5edef840 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -1,5 +1,5 @@ /* sexp.h -- header for sexp library */ -/* Copyright (c) 2009-2015 Alex Shinn. All rights reserved. */ +/* Copyright (c) 2009-2022 Alex Shinn. All rights reserved. */ /* BSD-style license: http://synthcode.com/license.txt */ #ifndef SEXP_H @@ -7,7 +7,7 @@ #ifdef __cplusplus extern "C" { -#define SEXP_FLEXIBLE_ARRAY [1] +#define SEXP_FLEXIBLE_ARRAY [SEXP_FLEXIBLE_ARRAY_SIZE] #else #define SEXP_FLEXIBLE_ARRAY [] #endif