How to handle portability issues in a binary file format
问题 I'm designing a binary file format to store strings[without terminating null to save space] and binary data. i. What is the best way to deal with little/big endian systems? i.a Would converting everything to network byte order and back with ntohl()/htonl() work? ii. Will the packed structures be the same size on x86, x64 and arm? iii. Are their any inherent weakness with this approach? struct __attribute__((packed)) Header { uint8_t magic; uint8_t flags; }; struct __attribute__((packed))