pad , 2 4, . #pragma, , , (, ).
.
- , , , , , . , , pragma pack, . , , , - .
C, , , : , ,
, #pragma pack (1) , , , , , , , . , , ; , , C : , :
void readStruct(header &h, std::ifstream file)
{
file.read((char*) &h.type, sizeof(char));
file.read((char *) &h.size, sizeof(short));
}
( , , )
, ++, - , myObject.readData(file). ?
Easier to read, maintain, compile, leads to faster and more optimized code, by default.
I usually don't like messing with the #pragma directives if I'm not sure what I'm doing. The consequences may be surprising.