I am running into issues with this assertion in the Win 10 SDK for Winnt.h, when upgrading from Win8.1 a C file which #includes winnt.h:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winnt.h(2487,1): error C2118: negative subscript
#if defined(__cplusplus) && (_MSC_VER >= 1600)
static_assert(__alignof(LARGE_INTEGER) == 8, "Windows headers require the default packing option. Changing this can lead to memory corruption."
" This diagnostic can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined.");
#elif _MSC_VER >= 1300
#pragma warning(push)
#pragma warning(disable: 4116)
C_ASSERT(TYPE_ALIGNMENT(LARGE_INTEGER) == 8); <========= LN2487
#pragma warning(pop)
#endif
#endif
The error is simply telling me the CASSERT failed, but I have explicitly set /Zp8 and that made no difference.
So I hacked Winnt.h:
// Much of the Windows SDK assumes the default packing of structs.
#if !defined(WINDOWS_IGNORE_PACKING_MISMATCH) && !defined(__midl) && !defined(MIDL_PASS) && !defined(SORTPP_PASS) && !defined(RC_INVOKED)
#if defined(__cplusplus) && (_MSC_VER >= 1600)
static_assert(__alignof(LARGE_INTEGER) == 8, "Windows headers require the default packing option. Changing this can lead to memory corruption."
" This diagnostic can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined.");
#elif _MSC_VER >= 1300
#pragma warning(push)
#pragma warning(disable: 4116)
#pragma pack(show)
C_ASSERT(TYPE_ALIGNMENT(LARGE_INTEGER) == 8);
#pragma warning(pop)
#endif
#endif
Test code:
#pragma pack(show)
#include "LibraryHeader.h" //somehow includes Windows.h
#pragma pack(show)
Now I get result:
value of pragma pack(show) == 8 value of pragma pack(show) == 4 value of pragma pack(show) == 8
So it seems the mess of 3rd party headers we are using must be causing this. Which is weird because it worked against the 8.1 SDK, and because the header itself explcitly tells us we must have 8-byte packing/alignment set in the compiler.
I guess the question comes down to: is there any way the W10 SDK is causing this given no code has changed and it compiles against W8.1 SDK? Or, has it always been like this and the W8.1 SDK failed to check?
