diff options
| author | Tyge Løvset <[email protected]> | 2022-02-04 15:53:28 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-02-04 15:53:28 +0100 |
| commit | 53de8174dd788db62c219477e9cca0ee3ce757cb (patch) | |
| tree | 923229e97cb41cfd41f0d7fea6bbf3ec12ac90e5 /include | |
| parent | ba3f9c10466bf724cada8713cd2934bdc56bb26e (diff) | |
| parent | 97fa2dc0a55a49818b12f475e2c163fa201bf2d0 (diff) | |
| download | STC-modified-53de8174dd788db62c219477e9cca0ee3ce757cb.tar.gz STC-modified-53de8174dd788db62c219477e9cca0ee3ce757cb.zip | |
Merge branch 'master' of github.com:tylov/STC
Diffstat (limited to 'include')
| -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) {
|
