A rather simple questions about safe ways to write constant in size structs (containing uint8_t, uint32_t etc) to binary file that would ensure it's readibility
Is it accepted to use
#pragma pack
? (similiar toBITMAPFILEHEADER
) and then writing entire struct to file (so far it worked with bitmaps). Should I rather use a simple serialization to single bytes ( as shown here Serialization of struct)?What about endianness? How should one prepare for switch to different one? Is forcing eg little endian only and requiring application (in BE) to byteswap each element accepted?
My current project is rather simple one, but I would like to expand it in the future so I would rather try to avoid any pitfalls. I know that boost offers serialization, but for know I would like to handle stuff manually.