summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-09 02:42:35 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-09 02:42:35 +0330
commit90690900cedbbf8004f5b452dae04166818f99fc (patch)
treeea066c3378ac6460e394f3d9ebe90a1707ad0d18 /src/utils
parentd76c19e0bea07806c49175c91d19eb38cfb230dd (diff)
convert assert to static_assert for no unnecesary runtime overhead
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/type.c30
-rw-r--r--src/utils/type.h3
2 files changed, 15 insertions, 18 deletions
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 <assert.h>
+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();