From ff366fba87b5486b75713cd3d95547d45f2b4824 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 19 Dec 2024 19:11:47 -0500
Subject: [PATCH] include: Move SDL_HAS_BUILTIN to SDL_begin_code.h, document
it.
This macro fits better here, since most of the other macros in this file are
for testing similar compiler/target features, etc.
---
include/SDL3/SDL_begin_code.h | 23 ++++++++++++++++++++++-
include/SDL3/SDL_stdinc.h | 11 -----------
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/include/SDL3/SDL_begin_code.h b/include/SDL3/SDL_begin_code.h
index 1df322967091e..95084b1c97132 100644
--- a/include/SDL3/SDL_begin_code.h
+++ b/include/SDL3/SDL_begin_code.h
@@ -262,10 +262,31 @@
*/
#define SDL_RESTRICT __restrict__
+/**
+ * Check if the compiler supports a given builtin functionality.
+ *
+ * This allows preprocessor checks for things that otherwise might fail
+ * to compile.
+ *
+ * Supported by virtually all clang versions and more-recent GCCs. Use this
+ * instead of checking the clang version if possible.
+ *
+ * On compilers without has_builtin support, this is defined to 0 (always false).
+ *
+ * \since This macro is available since SDL 3.1.3.
+ */
+#define SDL_HAS_BUILTIN(x) __has_builtin(x)
+
/* end of wiki documentation section. */
#endif
-
+#ifndef SDL_HAS_BUILTIN
+#ifdef __has_builtin
+#define SDL_HAS_BUILTIN(x) __has_builtin(x)
+#else
+#define SDL_HAS_BUILTIN(x) 0
+#endif
+#endif
#ifndef SDL_DEPRECATED
# if defined(__GNUC__) && (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h
index d9ef590c5f904..c7d0b85d9048f 100644
--- a/include/SDL3/SDL_stdinc.h
+++ b/include/SDL3/SDL_stdinc.h
@@ -147,17 +147,6 @@ void *alloca(size_t);
typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
#endif
-/**
- * Check if the compiler supports a given builtin.
- * Supported by virtually all clang versions and recent gcc. Use this
- * instead of checking the clang version if possible.
- */
-#ifdef __has_builtin
-#define SDL_HAS_BUILTIN(x) __has_builtin(x)
-#else
-#define SDL_HAS_BUILTIN(x) 0
-#endif
-
/**
* The number of elements in a static array.
*