CAlive will introduce the ability to define variable-length members for classes and structs.
struct S3_variableLengthMembers
{
u32 alength;
char a[0..alength];
u32 blength;
char b[0..blength];
u32 clength;
char c[0..clength];
};
In the above example, the S3_variableLengthMembers structure contains a fixed positioning of members, but their location in memory is not known until runtime. CAlive will automatically generate code to allow the variable locations of each member to be accessed properly. The minimum length is given first (0), and the maximum length is given by the variable. CAlive will compute the location of each member in a variable structure correctly, so they can be used as needed.
In addition, the need to add discriminating structure formats will be added. These allow multiple structures to be defined and, based on some test expression, the indicated format will go into scope for that instance when encountered. The testing is done top-down, and the first match is the one that's in scope. To explicitly make a particular form be in scope, use a name after the discr keyword, and assign it with that name, as in p = (S3_variableLengthMembers.name*)data;.
struct S3_variableLengthMembers
{{
discr (x == 3)
{
// Has three integer members
int x;
u32 a;
u32 b;
u32 c;
} else discr (x == 2) {
// Has two variable-length members
int x;
u32 alength;
char a[0..alength];
u32 blength;
char b[0..blength];
} else discr (x == 1) {
// Has one fixed length data member
int x;
char a[45];
} else {
// Unknown, so the pointer is set to a NULL for usage, but it remains where it is pointing.
// At this point it has the equivalent of pointing to an empty struct. Nothing will be able
// to be referenced, and ++, --, and other pointer math operations will not work.
discrnull;
}
}};
Pointers created by a discriminating structure will be twice the normal size, and will include an invisible hidden member indicating which discr { } block to use when processing the current instance.
Variable-length structs and classes defined in this way can be traversed forward. In order to go backward, they'll need to be defined with the -- keyword indicating they have an extra member at the end indicating how many bytes each variable-length block is.
struct -- S3_variableLengthMembers
{
u32 alength;
char a[0..alength];
u32 blength;
char b[0..blength];
u32 clength;
char c[0..clength];
};
The above example automatically adds an extra member that is the length of the struct, which appears immediately after the last member. So, when navigating backward CAlive will see that length, and go back accordingly.
--
Rick C. Hodgin