From 633fa48842b759ed97dfc72d6a165926ba1d4bae Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 31 Mar 2022 17:01:02 +0300 Subject: [PATCH] use _Static_assert for COMPILE_TIME_ASSERT if available --- Quake/q_stdinc.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Quake/q_stdinc.h b/Quake/q_stdinc.h index f600f8cf..73ad741b 100644 --- a/Quake/q_stdinc.h +++ b/Quake/q_stdinc.h @@ -89,8 +89,14 @@ /* Make sure the types really have the right * sizes: These macros are from SDL headers. */ -#define COMPILE_TIME_ASSERT(name, x) \ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#define COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x) +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +#define COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) +#else /* universal, but may trigger -Wunused-local-typedefs */ +#define COMPILE_TIME_ASSERT(name, x) \ typedef int dummy_ ## name[(x) * 2 - 1] +#endif COMPILE_TIME_ASSERT(char, sizeof(char) == 1); COMPILE_TIME_ASSERT(float, sizeof(float) == 4);