diff options
| author | Tyge Lovset <[email protected]> | 2022-02-03 13:29:24 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-02-03 13:29:24 +0100 |
| commit | 97fa2dc0a55a49818b12f475e2c163fa201bf2d0 (patch) | |
| tree | b4fdf8cfda3130e255d16071ee2f627b8dde45ce | |
| parent | df626f83dbf7789d622a1c5f4ff9fec3f61bc61b (diff) | |
| download | STC-modified-97fa2dc0a55a49818b12f475e2c163fa201bf2d0.tar.gz STC-modified-97fa2dc0a55a49818b12f475e2c163fa201bf2d0.zip | |
Fix c++ compability in cstr.
| -rw-r--r-- | include/stc/cstr.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index b99e5525..78fd4cce 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -32,14 +32,14 @@ #include <ctype.h>
#define cstr_npos (SIZE_MAX >> 1)
-typedef struct { size_t size, cap; char str[]; } _cstr_rep_t;
+typedef struct { size_t size, cap; char str[sizeof(size_t)]; } _cstr_rep_t;
#define _cstr_rep(self) c_container_of((self)->str, _cstr_rep_t, str)
#ifdef _i_static
- static const cstr cstr_null;
+ static _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
+ static const cstr cstr_null = {_cstr_nullrep.str};
#else
extern const cstr cstr_null;
#endif
-
/* optimal memory: based on malloc_usable_size() sequence: 24, 40, 56, ... */
#define _cstr_opt_mem(cap) ((((offsetof(_cstr_rep_t, str) + (cap) + 8)>>4)<<4) + 8)
/* optimal string capacity: 7, 23, 39, ... */
@@ -175,11 +175,10 @@ c_strncasecmp(const char* s1, const char* s2, size_t nmax) { /* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(_i_implement)
-static struct { size_t size, cap; char str[1]; } _cstr_nullrep = {0, 0, {0}};
-#ifdef _i_static
-static
-#endif
+#ifndef _i_static
+static struct _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
const cstr cstr_null = {_cstr_nullrep.str};
+#endif
STC_DEF size_t
cstr_reserve(cstr* self, const size_t cap) {
|
