Hacker News
points by spacechild1 1 day ago | 0 comments
One example that comes to my mind is libopus: https://github.com/xiph/opus

If you have structs that might need to be extended, you can use "versioned structs". One popular technique is to include the struct size as the first field. The struct size is set to `offsetof(mystruct, lastmember) + sizeof(lastmember)` and the receiver of the struct can use this to check if a member exists. The ARA API is a good example: https://github.com/Celemony/ARA_API/blob/65ec5c43b943a48cb54...

[–] agosz 12 hours ago
If you do version and size as the first two fields, you're basically there to backwards and forwards compatibility. Callers can request the size of the struct, allocate a buffer, and read out the parts they need. They can also check specific versions for what they support and ignore newer versions.

It also helps if you only append to the end of the struct for newer fields.

Hacker News