speaking of what c is about
Home About Articles Projects Posted 2015-10-12 A program I’ve been working on involves reading and writing different kinds of C structs to/from disk, and I’ve been trying to find a good way to reduce the code complexity and maintenance work involved in this task. In the course of these experiments, I created a somewhat interesting partial solution I thought would be worth sharing. At this stage, the structs only consist of primitive elements (int, float, char, etc). Handling nested structs, unions, bitfields and pointers would require additional work (that may be the subject of a future post.) My first approach involved writing separate serializing and deserializing functions for each struct type. The serialize (pack) function would convert the struct into a buffer of bytes. This buffer could then be written to disk. Later on, those bytes could be read back from the dis...