0xbadf00d
0xbadf00d

Reputation: 18178

cross-platform file structure handling

Whenever I need to define a file structure, I'm using compiler-specific commands (like #pragma pack(1)) to ensure that I can safely read and write this file and don't need to worry about padding issues.

However, is there any other way to reach the same goal? I don't need to de-/serialize complex objects, just POD types.

Upvotes: 2

Views: 189

Answers (2)

Bart van Ingen Schenau
Bart van Ingen Schenau

Reputation: 15768

It is impossible to define a cross-platform binary format that always nicely maps to the in-memory representation of types.

The two options for defining cross-platform file formats are:

  1. Use text
  2. Define a binary format in terms of what your favourite cross-platform serialisation library can provide and use that library to convert the file contents between their internal and external representation.

Upvotes: 2

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39370

Boost Serialization Library might be an option, if you want it to be solved fast and without much ado.

Upvotes: 0

Related Questions