From 9f1a51593ae7dd45db46f39ac18901ad175af18e Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 4 Mar 2022 20:21:29 +0100 Subject: Replaced c_strlit type with c_strlen_lit(lit) macro and its usage. --- include/stc/alt/cstr.h | 2 +- include/stc/cbits.h | 2 +- include/stc/ccommon.h | 2 +- include/stc/cstr.h | 2 +- include/stc/csview.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index adad3e3d..82ebae91 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -82,7 +82,7 @@ STC_INLINE _cstr_rep_t cstr_rep_(cstr* self) { /**************************** PUBLIC API **********************************/ -#define cstr_new(literal) cstr_from_n(literal, sizeof((c_strlit){literal}) - 1) +#define cstr_new(literal) cstr_from_n(literal, c_strlen_lit(literal)) #define cstr_npos (SIZE_MAX >> 1) #define cstr_null (c_make(cstr){.sso = {.cap_len = SSO_CAP}}) #define cstr_toraw(self) cstr_str(self) diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 6c2235e7..af9336c1 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -78,7 +78,7 @@ STC_INLINE void cbits_drop(cbits* self) { c_free(self->data64); } STC_INLINE size_t cbits_size(cbits set) { return set.size; } #define cbits_new(literal) \ - cbits_from_n(literal, sizeof c_make(c_strlit){literal} - 1) + cbits_from_n(literal, c_strlen_lit(literal)) STC_INLINE cbits* cbits_take(cbits* self, cbits other) { if (self->data64 != other.data64) {cbits_drop(self); *self = other;} diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 263971a0..52daf837 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -77,7 +77,7 @@ # define c_free(p) free(p) #endif -typedef const char c_strlit[]; +#define c_strlen_lit(literal) (sizeof "" literal - 1U) #define c_delete(T, ptr) do { T *_c_p = ptr; T##_drop(_c_p); c_free(_c_p); } while (0) #define c_swap(T, x, y) do { T _c_t = x; x = y; y = _c_t; } while (0) #define c_arraylen(a) (sizeof (a)/sizeof (a)[0]) diff --git a/include/stc/cstr.h b/include/stc/cstr.h index fc4c22d1..9ddf3d32 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -68,7 +68,7 @@ STC_INLINE cstr cstr_init() { return cstr_null; } #define cstr_str(self) (self)->str #define cstr_toraw(self) (self)->str #define cstr_new(literal) \ - cstr_from_n(literal, sizeof c_make(c_strlit){literal} - 1) + cstr_from_n(literal, c_strlen_lit(literal)) STC_INLINE cstr cstr_from(const char* str) { return cstr_from_n(str, strlen(str)); } STC_INLINE char* cstr_data(cstr* self) { return self->str; } diff --git a/include/stc/csview.h b/include/stc/csview.h index c2bd041d..85ade552 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -38,7 +38,7 @@ STC_API csview csview_slice(csview sv, intptr_t p1, intptr_t p2); STC_API csview csview_token(csview sv, csview sep, size_t* start); #define csview_new(literal) \ - c_make(csview){literal, sizeof c_make(c_strlit){literal} - 1} + c_make(csview){literal, c_strlen_lit(literal)} STC_INLINE csview csview_init() { return csview_null; } STC_INLINE csview csview_from(const char* str) { return c_make(csview){str, strlen(str)}; } -- cgit v1.2.3