April 22nd, 2009

What structure packing do the Windows SDK header files expect?

/Zp8

In words, integral types and pointers up to eight bytes in size are stored at their natural alignment. Larger types are stored at eight-byte alignment.

Type Alignment
BYTE, char, UCHAR 1-byte alignment
WORD, WCHAR, short, USHORT 2-byte alignment
DWORD, int, long, UINT, ULONG, float, 32-bit pointer 4-byte alignment
QWORD, __int64, unsigned __int64, double, 64-bit pointer 8-byte alignment

In other words (saying it a third time), let T be an integral or pointer type. If sizeof(T) ≤ 8, then T is aligned at a sizeof(T)-byte boundary. If sizeof(T) ≥ 8, then T is aligned at an 8-byte boundary.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.