On Aug 19, 8:55 pm, CBFalconer <cbfalco...@yah oo.comwrote:
The 'library' is not defined in the C standard. Unless you post
the C-standard code involved here the question remains off-topic.
Although he's working with the library, he's asking a fairly general
question pertaining to the capabilities of C as a language: whether
it's possible to serialize a structure without knowing the structure
of its fields in a way that will work even if the structure layout is
changed.
In short, the answer is no because fwrite() and fread() only work on
raw bytes, and there's no telling what the internal representations
for the fields present in the structure are, or whether there are any
padding bytes, etc. It seems, however, that the library you're using
provides *a* solution, even if it's not the optimal one. Luckily, if
you're doing file I/O, that's probably the real bottleneck, as opposed
to preparing the data for output and reconstructing it from input.