From 90690900cedbbf8004f5b452dae04166818f99fc Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 9 Apr 2025 02:42:35 +0330 Subject: convert assert to static_assert for no unnecesary runtime overhead --- src/utils/type.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/utils/type.c') diff --git a/src/utils/type.c b/src/utils/type.c index a46be5a..09b9c36 100644 --- a/src/utils/type.c +++ b/src/utils/type.c @@ -1,24 +1,20 @@ #include "type.h" -#include +static_assert(sizeof(bool) == (8 / 8), "Bad size"); -void checkTypes() { - assert(sizeof(bool) == (8 / 8)); +static_assert(sizeof(i8) == (8 / 8), "Bad size"); +static_assert(sizeof(i16) == (16 / 8), "Bad size"); +static_assert(sizeof(i32) == (32 / 8), "Bad size"); +static_assert(sizeof(i64) == (64 / 8), "Bad size"); - assert(sizeof(i8) == (8 / 8)); - assert(sizeof(i16) == (16 / 8)); - assert(sizeof(i32) == (32 / 8)); - assert(sizeof(i64) == (64 / 8)); - - assert(sizeof(u8) == (8 / 8)); - assert(sizeof(u16) == (16 / 8)); - assert(sizeof(u32) == (32 / 8)); - assert(sizeof(u64) == (64 / 8)); +static_assert(sizeof(u8) == (8 / 8), "Bad size"); +static_assert(sizeof(u16) == (16 / 8), "Bad size"); +static_assert(sizeof(u32) == (32 / 8), "Bad size"); +static_assert(sizeof(u64) == (64 / 8), "Bad size"); #ifdef FLOAT_16_SUPPORT - assert(sizeof(f16) == (16 / 8)); +static_assert(sizeof(f16) == (16 / 8), "Bad size"); #endif - assert(sizeof(f32) == (32 / 8)); - assert(sizeof(f64) == (64 / 8)); - assert(sizeof(f128) == (128 / 8)); -} +static_assert(sizeof(f32) == (32 / 8), "Bad size"); +static_assert(sizeof(f64) == (64 / 8), "Bad size"); +static_assert(sizeof(f128) == (128 / 8), "Bad size"); -- cgit v1.2.3