What does the following statement actually do and what are it's effects?
#pragma pack(push,8)
What does the following statement actually do and what are it's effects?
#pragma pack(push,8)
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.
char
, short
, long
, double
). Then determine the size of the structure using sizeof
. Place a pair of #pragma pack(push, n)
and #pragma pack(pop)
around the structure with different values for n
(e.g. 1, 2, 4, 8). See how sizeof
's results change. As an option, check out the change in relative addressing of the structure's elements. –
Fresh © 2022 - 2024 — McMap. All rights reserved.