Add SDL_PRILL? format specifiers specifically for long long type.

This commit is contained in:
Ozkan Sezer 2024-09-19 21:43:55 +03:00 committed by Ozkan Sezer
parent 6f80d47d64
commit 254b36361e
2 changed files with 41 additions and 29 deletions

View file

@ -100,6 +100,25 @@ void *alloca(size_t);
# define SDL_SIZE_MAX ((size_t) -1) # define SDL_SIZE_MAX ((size_t) -1)
#endif #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. * Check if the compiler supports a given builtin.
* Supported by virtually all clang versions and recent gcc. Use this * Supported by virtually all clang versions and recent gcc. Use this
@ -408,7 +427,7 @@ typedef Sint64 SDL_Time;
/* @} *//* Floating-point constants */ /* @} *//* Floating-point constants */
/* Make sure we have macros for printing width-based integers. /* Make sure we have macros for printing width-based integers.
* <stdint.h> should define these but this is not true all platforms. * <inttypes.h> should define these but this is not true all platforms.
* (for example win32) */ * (for example win32) */
#ifndef SDL_PRIs64 #ifndef SDL_PRIs64
#if defined(SDL_PLATFORM_WINDOWS) #if defined(SDL_PLATFORM_WINDOWS)
@ -482,6 +501,25 @@ typedef Sint64 SDL_Time;
#define SDL_PRIX32 "X" #define SDL_PRIX32 "X"
#endif #endif
#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 */ /* Annotations to help code analysis tools */
#ifdef SDL_DISABLE_ANALYZE_MACROS #ifdef SDL_DISABLE_ANALYZE_MACROS
@ -539,25 +577,6 @@ typedef Sint64 SDL_Time;
#endif #endif
#endif /* SDL_DISABLE_ANALYZE_MACROS */ #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 */ /** \cond */
#ifndef DOXYGEN_SHOULD_IGNORE_THIS #ifndef DOXYGEN_SHOULD_IGNORE_THIS
SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1); SDL_COMPILE_TIME_ASSERT(bool_size, sizeof(bool) == 1);

View file

@ -714,15 +714,8 @@ static int SDLCALL stdlib_getsetenv(void *arg)
#endif #endif
#endif #endif
#ifndef SDL_PLATFORM_WINDOWS #define FMT_PRILLd "%" SDL_PRILLd
#define FMT_PRILLd "%lld" #define FMT_PRILLu "%" SDL_PRILLu
#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
/** /**
* Call to SDL_sscanf * Call to SDL_sscanf