Answer the question
In order to leave comments, you need to log in
Qt data types?
When saving to a structure file, for example:
struct TEST_STRUCT <br/>
{<br/>
char descriptor[16];<br/>
DWORD val1;<br/>
BYTE val2;<br/>
};<br/>
Answer the question
In order to leave comments, you need to log in
#pragma pack (push, 1)
struct TEST_STRUCT
{
char descriptor[16];
DWORD val1;
BYTE val2;
};
#pragma pack (pop)
The answer to “why?”: Structures and classes in C ++ are aligned in memory to a multiple of the machine word by default, in this case 21 was rounded up to 24.
How to solve the problem has already been answered.
About "why" - not really. each variable will be rounded to the machine word. that is, you have 16 + 4 + 4.
And if there is BYTE, DOUBLE, BYTE, then the result will not be 1 + 8 + 1 = 10 -> 12, but 4 + 8 + 4 = 16!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question