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)) ) \