Added static assert + verify int type sizes

This commit is contained in:
Joel Höner 2017-11-26 05:33:37 +01:00
parent 56f47f4863
commit 486add62ed
2 changed files with 20 additions and 0 deletions

View File

@ -86,6 +86,17 @@
# endif
#endif
// Verify assumptions.
ZYDIS_STATIC_ASSERT(sizeof(ZydisU8) == 1);
ZYDIS_STATIC_ASSERT(sizeof(ZydisU16) == 2);
ZYDIS_STATIC_ASSERT(sizeof(ZydisU32) == 4);
ZYDIS_STATIC_ASSERT(sizeof(ZydisU64) == 8);
ZYDIS_STATIC_ASSERT(sizeof(ZydisI8) == 1);
ZYDIS_STATIC_ASSERT(sizeof(ZydisI16) == 2);
ZYDIS_STATIC_ASSERT(sizeof(ZydisI32) == 4);
ZYDIS_STATIC_ASSERT(sizeof(ZydisI64) == 8);
ZYDIS_STATIC_ASSERT(sizeof(ZydisUSize) == sizeof(ZydisISize));
/* ============================================================================================== */
/* NULL */
/* ============================================================================================== */

View File

@ -164,6 +164,15 @@
/* Utils */
/* ============================================================================================== */
/**
* @brief Compiler-time assertion.
*/
#if __STDC_VERSION__ >= 201112L
# define ZYDIS_STATIC_ASSERT(x) _Static_assert(x, #x)
#else
# define ZYDIS_STATIC_ASSERT(x) typedef int ZYDIS_SASSERT_IMPL[(x) ? 1 : -1]
#endif
/**
* @brief Declares a bitfield.
*/