From d269c239486c696ddec5fd390ba1a8e781386f1c Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Fri, 16 Mar 2018 23:00:46 +0100 Subject: [PATCH] Remove warning with C++. It'll will increase the size of the type a little bit. TODO: Check compatibility between code using C def and code using C++ def --- m-deque.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/m-deque.h b/m-deque.h index 07da13cd..203d5b26 100644 --- a/m-deque.h +++ b/m-deque.h @@ -46,6 +46,14 @@ #define DEQUEUI_DEFAULT_SIZE 8 +/* C++ doesn't support flexible array within a structure. + Let's define at least one element. */ +#ifdef __cplusplus +# define DEQUEI_MIN_ARRAY_SIZE 1 +#else +# define DEQUEI_MIN_ARRAY_SIZE +#endif + #define DEQUEI_CONTRACT(d) do { \ assert ((d) != NULL); \ assert ((d)->default_size >= DEQUEUI_DEFAULT_SIZE); \ @@ -66,7 +74,7 @@ typedef struct M_C(name, _node_s) { \ ILIST_INTERFACE(M_C(name, _node_list), struct M_C(name, _node_s)); \ size_t size; \ - type data[]; \ + type data[DEQUEI_MIN_ARRAY_SIZE]; \ } node_t; \ \ ILIST_DEF(M_C(name, _node_list), node_t, (DEL(M_GET_FREE oplist)) ) \