I have written a program using Visual Studio 2019. But I’m getting this error:
1>C:Program Files (x86)Windows
Kits10Include10.0.18362.0umwinnt.h(2487,1): error C2118: negative subscript
This is because structures are not 8 byte aligned. Here is the macro in Winnt.h that is being used to determine that:
C_ASSERT(TYPE_ALIGNMENT(LARGE_INTEGER) == 8);
I have selected 8 byte alignment in the properties. To determine what the TYPE_ALIGNMENT is generating I wrote a small program to print the result. The result is 4.
There must be another setting that I’m missing. Does anyone know how to fix this?
Following is a clip from the Winnt.h code:
// 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)
C_ASSERT(TYPE_ALIGNMENT(LARGE_INTEGER) == 8);
#pragma warning(pop)
#endif