From 2361cf8508b85969f1db8a4c6be9559a9522d572 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 8 Aug 2019 04:10:20 +0000 Subject: [PATCH] added static assertion macros --- qse/include/qse/macros.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/qse/include/qse/macros.h b/qse/include/qse/macros.h index cc62c599..6b1413f8 100644 --- a/qse/include/qse/macros.h +++ b/qse/include/qse/macros.h @@ -72,6 +72,14 @@ # undef QSE_HAVE_INLINE_NEVER #endif + +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)) +# define QSE_UNUSED __attribute__((__unused__)) +#else +# define QSE_UNUSED +#endif + + #if defined(_WIN32) || (defined(__WATCOMC__) && !defined(__WINDOWS_386__)) # define QSE_IMPORT __declspec(dllimport) # define QSE_EXPORT __declspec(dllexport) @@ -364,6 +372,22 @@ QSE_EXPORT void qse_assert_failed ( #endif +/* ========================================================================= + * STATIC ASSERTION + * =========================================================================*/ +#define QSE_STATIC_JOIN_INNER(x, y) x ## y +#define QSE_STATIC_JOIN(x, y) QSE_STATIC_JOIN_INNER(x, y) + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define QSE_STATIC_ASSERT(expr) _Static_assert (expr, "invalid assertion") +#elif defined(__cplusplus) && (__cplusplus >= 201103L) +# define QSE_STATIC_ASSERT(expr) static_assert (expr, "invalid assertion") +#else +# define QSE_STATIC_ASSERT(expr) typedef char QSE_STATIC_JOIN(QSE_STATIC_ASSERT_T_, __LINE__)[(expr)? 1: -1] QSE_UNUSED +#endif + +#define QSE_STATIC_ASSERT_EXPR(expr) ((void)QSE_SIZEOF(char[(expr)? 1: -1])) + /* ---------------------------------------------------------------------- * INTEGER LIMITS * ---------------------------------------------------------------------- */