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/main.c | 1 - src/utils/type.c | 30 +++++++++++++----------------- src/utils/type.h | 3 ++- 3 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 3513ff3..7518414 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,6 @@ int run(const char *filePath, bool shouldPrint) { } int main(int argc, char *argv[]) { - checkTypes(); fileInit(); if (argc < 2) { 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"); diff --git a/src/utils/type.h b/src/utils/type.h index ed0dd6f..4c61bc3 100644 --- a/src/utils/type.h +++ b/src/utils/type.h @@ -28,7 +28,8 @@ typedef long double f128; typedef u8 bool; #define false (bool)0 #define true (bool)1 + +#define static_assert _Static_assert #endif #endif -void checkTypes(); -- cgit v1.2.3