Search code examples
c++pragmapragma-pack

C++ #pragma pack


What does the following statement actually do and what are it's effects?

#pragma pack(push,8)

Solution

  • It pushes the current pack setting onto a stack (so that you can restore it later via pop) and then sets the alignment for struct elements to 8 bytes. Anything which is not naturally aligned to an 8 byte boundary will have padding bytes inserted before it to maintain the required alignment.