[fpc-devel] JWA 64-bit struct packing

Henry Vermaak henry.vermaak at gmail.com
Thu May 14 18:39:55 CEST 2020


On Thu, 14 May 2020 at 16:03, Henry Vermaak <henry.vermaak at gmail.com> wrote:

> So why is rtl/win*/* full of packrecords c?  These pages say that the
> Windows API expect 8:
>
> https://docs.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers#controlling-structure-packing
> https://docs.microsoft.com/en-gb/cpp/build/reference/zp-struct-member-alignment

If I do something like `echo '#include <wincred.h>' | gcc -E -dMD -P -
| grep -i pack` I get this:

#undef _CRT_PACKING
#define _CRT_PACKING 8
#pragma pack(push,_CRT_PACKING)
#pragma pack(pop)

Before any of wincred.h gets defined, so the packing gets popped and
it'll use the natural packing for the structs in wincred.h, which is
why packrecords c works in my code.  How does one know which header
uses 8 bytes and which uses natural packing?  (Apart from checking
mingw like this, which to be fair has never let me down with winapi
programming).

Henry


More information about the fpc-devel mailing list