Versioned Records
Implied Version
- Just take
sizeof(thing_t)
as the version - It's what Microsoft does for 20+ years.
x.version=sizeof(thing_t)
mantra is easy.
typedef struct _thing {
int version;
} thing_t;
thing_t something;
something.version = sizeof(thing_t);
do_it_live(something);
Explicit Version
- Have a version field and always set it to the latest version (ex. a constant
THING_CURRENT
.) - Full freedom to remove and replace old fields.
- Have to keep copies of old structures around forever though.
typedef struct _thing {
int version;
/* current version */
} current_thing_t;
typedef struct _thing {
int version;
/* fields when we changed some stuff */
} thing_v2_t;
typedef _thing {
int version;
/* fields from version one */
} thing_v1_t;
Entry points have to switch on the version then look up the runtime for the particular thing_v1_t
, or, perform an upgrade procedure that brings that old version to current.