From a52d901f25ed75eb06ea7637f8455fa22900fa81 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 20 Sep 2022 21:55:28 +0300 Subject: [PATCH] common: add STATIC_ASSERT macro We're trying to guess if we have C11 static_assert defined in assert.h otherwise use good ol' trick with negative array --- common/xash3d_types.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/xash3d_types.h b/common/xash3d_types.h index 33f82bb1..9b343e8c 100644 --- a/common/xash3d_types.h +++ b/common/xash3d_types.h @@ -10,6 +10,7 @@ #include // off_t #include STDINT_H +#include typedef unsigned char byte; typedef int sound_t; @@ -103,6 +104,11 @@ typedef uint64_t longtime_t; #define likely(x) (x) #endif +#if defined( static_assert ) // C11 static_assert +#define STATIC_ASSERT static_assert +#else +#define STATIC_ASSERT( x, y ) extern int _static_assert_##__LINE__[( x ) ? 1 : -1] +#endif #ifdef XASH_BIG_ENDIAN #define LittleLong(x) (((int)(((x)&255)<<24)) + ((int)((((x)>>8)&255)<<16)) + ((int)(((x)>>16)&255)<<8) + (((x) >> 24)&255))