use _Static_assert for SDL_COMPILE_TIME_ASSERT(), when available

This commit is contained in:
Ozkan Sezer 2022-03-17 14:56:04 +03:00 committed by Sam Lantinga
parent dfbe1f7248
commit f0d2747df1
1 changed files with 6 additions and 0 deletions

View File

@ -354,8 +354,14 @@ typedef uint64_t Uint64;
#endif #endif
#endif /* SDL_DISABLE_ANALYZE_MACROS */ #endif /* SDL_DISABLE_ANALYZE_MACROS */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x);
#elif defined(__cplusplus) && (__cplusplus >= 201103L)
#define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x);
#else /* universal, but may trigger -Wunused-local-typedefs */
#define SDL_COMPILE_TIME_ASSERT(name, x) \ #define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1] 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(uint8, sizeof(Uint8) == 1); SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);