]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
common: Define DP_STATIC_ASSERT which wraps static_assert
authorCloudwalk <cloudwalk009@gmail.com>
Tue, 20 Jul 2021 18:14:54 +0000 (14:14 -0400)
committerCloudwalk <cloudwalk009@gmail.com>
Tue, 20 Jul 2021 18:14:54 +0000 (14:14 -0400)
common.h
sys_sdl.c

index 5338d514ef60bc7ab5116d70b27dc592e223d15b..d71899fe446a58abedfb401dc5a011b5d4d47c0e 100644 (file)
--- a/common.h
+++ b/common.h
@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define COMMON_H
 
 #include <stdarg.h>
+#include <assert.h>
 #include "qtypes.h"
 #include "qdefs.h"
 
@@ -216,6 +217,12 @@ void COM_InitGameType (void);
 char *va(char *buf, size_t buflen, const char *format, ...) DP_FUNC_PRINTF(3);
 // does a varargs printf into provided buffer, returns buffer (so it can be called in-line unlike dpsnprintf)
 
+// GCC with -Werror=c++-compat will error out if static_assert is used even though the macro is valid C11...
+#ifndef __cplusplus
+#define DP_STATIC_ASSERT(expr, str) _Static_assert(expr, str)
+#else
+#define DP_STATIC_ASSERT(expr, str) static_assert(expr, str)
+#endif
 
 // snprintf and vsnprintf are NOT portable. Use their DP counterparts instead
 #ifdef snprintf
index 50cca9d99d5688c2e3442caf963f04e8bfbcfe3a..15a626d315421a89358ba4a910031d77441b6a19 100644 (file)
--- a/sys_sdl.c
+++ b/sys_sdl.c
@@ -1,5 +1,3 @@
-#include "darkplaces.h"
-
 #ifdef WIN32
 #include <io.h>
 #include "conio.h"
 
 #include <signal.h>
 
+/*
+ * Include this BEFORE darkplaces.h because it breaks wrapping
+ * _Static_assert. Cloudwalk has no idea how or why so don't ask.
+ */
 #include <SDL.h>
 
+#include "darkplaces.h"
+
 #ifdef WIN32
 #ifdef _MSC_VER
 #pragma comment(lib, "sdl2.lib")