mercredi 29 avril 2015

Compile-time integrity verification of versioned struct

I have a struct called FOO that's versioned, so we have FOO_V0, FOO_V1, and FOO_V2. This is legacy architecture so I am currently not at a liberty to change it. However, I wanted to see if I could insert some compile-time checks such as static_assert that make sure FOO_V0 + d is F00_V1 and FOO_V1 + e is FOO_V2 so the integrity is somewhat enforced. Is that possible? TIA for any feedback!

typedef struct FOO_V0
{
    UINT a;   
    BOOL b;
    LARGE_INTEGER c;
} FOO_V0;

typedef struct FOO_V1
{
    UINT a;   
    BOOL b;
    LARGE_INTEGER c;
    UINT d;
} FOO_V1;

typedef struct FOO_V2
{
    UINT a;   
    BOOL b;
    LARGE_INTEGER c;
    UINT d;
    BOOL e;
} FOO_V2;

Thanks.

Aucun commentaire:

Enregistrer un commentaire