#pragma pack(n), where n is 1, 2, 4, 8, or 16:
each structure member after the first is stored on the smaller member type or n-byte boundaries.
A example will give a more direct impression:
while
PS. There is a little funny when I first encounter this preprocessor. I guess pack(8) is to force to align at 8b, but in fact the true meaning is 8B.
each structure member after the first is stored on the smaller member type or n-byte boundaries.
A example will give a more direct impression:
#pragma pack(8)
struct A {
char c;
int i;
};
so sizeof(A) is 8;struct A {
char c;
int i;
};
while
#pragma pack(1)
struct A {
char c;
int i;
};
then sizeof(A) is 5.struct A {
char c;
int i;
};
PS. There is a little funny when I first encounter this preprocessor. I guess pack(8) is to force to align at 8b, but in fact the true meaning is 8B.
浙公网安备 33010602011771号