From 2dcac231b5eea841f7bc607f0ddbc729bc41a9e5 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 9 Sep 2021 17:07:32 +0200 Subject: Made c_static_assert() C99 compatible (which was the point of it). --- examples/phonebook.c | 2 +- include/stc/ccommon.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/phonebook.c b/examples/phonebook.c index a4e2e0f2..a0aee757 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -39,7 +39,7 @@ void print_phone_book(cmap_str phone_book) int main(int argc, char **argv) { - c_static_assert(3 == 3, "hello"); + c_static_assert(sizeof argc == 4); c_forauto (cset_str, names) { c_emplace (cset_str, names, {"Hello", "Cool", "True"}); diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 8250c4b6..b4679998 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -68,9 +68,10 @@ _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, \ _23, _24, _25, _26, _27, _28, _29, _30, N, ...) N -#define c_static_assert(cond, ...) typedef char _static_assert_[(cond) ? 1 : -1] +#define c_static_assert(cond) \ + typedef char c_PASTE(_static_assert_line_, __LINE__)[(cond) ? 1 : -1] #define c_container_of(ptr, type, member) \ - ((type *)((char *)(ptr) - offsetof(type, member))) + ((type *)((char *)(ptr) - offsetof(type, member))) #if __cplusplus #define c_new(T) static_cast(c_malloc(sizeof(T))) -- cgit v1.2.3