From 378ec87619430d706b954bfc2daee30df6c052d3 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 24 Jan 2016 12:56:38 +0100 Subject: [PATCH] More assertions. --- src/STDInclude.cpp | 33 +++++++++++++++++++++++++++++++++ src/STDInclude.hpp | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/STDInclude.cpp b/src/STDInclude.cpp index 7a1e538d..dd52bc10 100644 --- a/src/STDInclude.cpp +++ b/src/STDInclude.cpp @@ -1,11 +1,44 @@ #include "STDInclude.hpp" // Do necessary assertions here +// Some compilers treat them differently which causes a size mismatch + +// WinAPI types Assert_Size(DWORD, 4); Assert_Size(WORD, 2); Assert_Size(BYTE, 1); +// 64 bit integers +Assert_Size(__int64, 8); +Assert_Size(unsigned __int64, 8); Assert_Size(long long, 8); +Assert_Size(unsigned long long, 8); +Assert_Size(int64_t, 8); +Assert_Size(uint64_t, 8); + +// 32 bit integers +Assert_Size(__int32, 4); +Assert_Size(unsigned __int32, 4); Assert_Size(int, 4); +Assert_Size(unsigned int, 4); +Assert_Size(int32_t, 4); +Assert_Size(uint32_t, 4); + +// 16 bit integers +Assert_Size(__int16, 2); +Assert_Size(unsigned __int16, 2); Assert_Size(short, 2); +Assert_Size(unsigned short, 2); +Assert_Size(int16_t, 2); +Assert_Size(uint16_t, 2); + +// 8 bit integers +Assert_Size(__int8, 1); +Assert_Size(unsigned __int8, 1); Assert_Size(char, 1); +Assert_Size(unsigned char, 1); +Assert_Size(int8_t, 1); +Assert_Size(uint8_t, 1); + +// Ensure pointers are 4 bytes in size (32-bit) +static_assert(sizeof(intptr_t) == 4 && sizeof(void*) == 4 && sizeof(size_t) == 4, "This doesn't seem to be a 32-bit environment!"); diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index 6f80f69a..68613666 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -88,4 +88,4 @@ #define VERSION 4,2,REVISION #define VERSION_STR "4.2." REVISION_STR -#define Assert_Size(x, size) static_assert(sizeof(x) == size, STRINGIZE(x) " structure has an invalid size."); +#define Assert_Size(x, size) static_assert(sizeof(x) == size, STRINGIZE(x) " structure has an invalid size.")