From 2df43a26d52086cbd68dd0917dd39e966eb1e82e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 18 Jun 2023 09:59:12 +0100 Subject: [PATCH] sync with yquake2 --- src/common/header/shared.h | 5 +++++ src/common/shared.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/header/shared.h b/src/common/header/shared.h index 4382603..72e7bfb 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -60,6 +60,7 @@ typedef unsigned char byte; #define YQ2_ALIGNAS_TYPE(TYPE) _Alignas(TYPE) // must be used as prefix (YQ2_ATTR_NORETURN void bla();)! #define YQ2_ATTR_NORETURN _Noreturn + #define YQ2_STATIC_ASSERT(C, M) _Static_assert((C), M) # if defined(__GNUC__) #define YQ2_ATTR_MALLOC __attribute__ ((__malloc__)) #define YQ2_ATTR_INLINE __attribute__((always_inline)) inline @@ -77,6 +78,8 @@ typedef unsigned char byte; #define YQ2_ATTR_NORETURN __attribute__ ((noreturn)) #define YQ2_ATTR_MALLOC __attribute__ ((__malloc__)) #define YQ2_ATTR_INLINE __attribute__((always_inline)) inline + // GCC supports this extension since 4.6 + #define YQ2_STATIC_ASSERT(C, M) _Static_assert((C), M) #elif defined(_MSC_VER) // Note: We prefer VS2019 16.8 or newer in C11 mode (/std:c11), // then the __STDC_VERSION__ >= 201112L case above is used @@ -95,6 +98,7 @@ typedef unsigned char byte; #define YQ2_ATTR_NORETURN __declspec(noreturn) #define YQ2_ATTR_MALLOC __declspec(restrict) #define YQ2_ATTR_INLINE __forceinline + #define YQ2_STATIC_ASSERT(C, M) assert((C) && M) #else #warning "Please add a case for your compiler here to align correctly" #define YQ2_ALIGNAS_SIZE(SIZE) @@ -102,6 +106,7 @@ typedef unsigned char byte; #define YQ2_ATTR_NORETURN #define YQ2_ATTR_MALLOC #define YQ2_ATTR_INLINE inline + #define YQ2_STATIC_ASSERT(C, M) assert((C) && M) #endif #if defined(__GNUC__) diff --git a/src/common/shared.c b/src/common/shared.c index e7b792a..471a471 100644 --- a/src/common/shared.c +++ b/src/common/shared.c @@ -868,7 +868,7 @@ Swap_Init(void) { byte swaptest[2] = {1, 0}; short swapTestShort; - assert(sizeof(short) == 2); + YQ2_STATIC_ASSERT(sizeof(short) == 2, "invalid short size"); memcpy(&swapTestShort, swaptest, 2); /* set the byte swapping variables in a portable manner */