From 254b36361e575fe9add02003de7fa8589a104b78 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 19 Sep 2024 21:43:55 +0300 Subject: [PATCH] Add SDL_PRILL? format specifiers specifically for long long type. --- include/SDL3/SDL_stdinc.h | 59 ++++++++++++++++++++++++------------ test/testautomation_stdlib.c | 11 ++----- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h index 8818cda584..cdc6e10635 100644 --- a/include/SDL3/SDL_stdinc.h +++ b/include/SDL3/SDL_stdinc.h @@ -100,6 +100,25 @@ void *alloca(size_t); # define SDL_SIZE_MAX ((size_t) -1) #endif +#ifndef SDL_COMPILE_TIME_ASSERT +#if defined(__cplusplus) +/* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */ +#if (__cplusplus >= 201103L) +#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) +#endif +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) +#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x) +#endif +#endif /* !SDL_COMPILE_TIME_ASSERT */ + +#ifndef SDL_COMPILE_TIME_ASSERT +/* universal, but may trigger -Wunused-local-typedefs */ +#define SDL_COMPILE_TIME_ASSERT(name, x) \ + 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 @@ -408,7 +427,7 @@ typedef Sint64 SDL_Time; /* @} *//* Floating-point constants */ /* Make sure we have macros for printing width-based integers. - * should define these but this is not true all platforms. + * should define these but this is not true all platforms. * (for example win32) */ #ifndef SDL_PRIs64 #if defined(SDL_PLATFORM_WINDOWS) @@ -482,6 +501,25 @@ typedef Sint64 SDL_Time; #define SDL_PRIX32 "X" #endif #endif +/* Specifically for the `long long` -- SDL-specific. */ +#ifndef SDL_PLATFORM_WINDOWS +#define SDL_PRILL_PREFIX "ll" +#else +SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */ +#define SDL_PRILL_PREFIX "I64" +#endif +#ifndef SDL_PRILLd +#define SDL_PRILLd SDL_PRILL_PREFIX "d" +#endif +#ifndef SDL_PRILLu +#define SDL_PRILLu SDL_PRILL_PREFIX "u" +#endif +#ifndef SDL_PRILLx +#define SDL_PRILLx SDL_PRILL_PREFIX "x" +#endif +#ifndef SDL_PRILLX +#define SDL_PRILLX SDL_PRILL_PREFIX "X" +#endif /* Annotations to help code analysis tools */ #ifdef SDL_DISABLE_ANALYZE_MACROS @@ -539,25 +577,6 @@ typedef Sint64 SDL_Time; #endif #endif /* SDL_DISABLE_ANALYZE_MACROS */ -#ifndef SDL_COMPILE_TIME_ASSERT -#if defined(__cplusplus) -/* Keep C++ case alone: Some versions of gcc will define __STDC_VERSION__ even when compiling in C++ mode. */ -#if (__cplusplus >= 201103L) -#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) -#endif -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) -#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x) -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x) -#endif -#endif /* !SDL_COMPILE_TIME_ASSERT */ - -#ifndef SDL_COMPILE_TIME_ASSERT -/* universal, but may trigger -Wunused-local-typedefs */ -#define SDL_COMPILE_TIME_ASSERT(name, x) \ - typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1] -#endif - /** \cond */ #ifndef DOXYGEN_SHOULD_IGNORE_THIS SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1); diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c index 26594e8279..b3ed82ab71 100644 --- a/test/testautomation_stdlib.c +++ b/test/testautomation_stdlib.c @@ -714,15 +714,8 @@ static int SDLCALL stdlib_getsetenv(void *arg) #endif #endif -#ifndef SDL_PLATFORM_WINDOWS -#define FMT_PRILLd "%lld" -#define FMT_PRILLu "%llu" -#else -/* make sure long long is 64 bits */ -SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); -#define FMT_PRILLd "%I64d" -#define FMT_PRILLu "%I64u" -#endif +#define FMT_PRILLd "%" SDL_PRILLd +#define FMT_PRILLu "%" SDL_PRILLu /** * Call to SDL_sscanf