CAlive will introduce named members that can be accessed before a struct or class. These pre members do not normally exist, but can be referenced in special cases. To allocate for them, a struct or class should be created with
prenew and released with
predelete, which will use the full size. Otherwise it will only use the standard size without the
pre {..} block.
pre {
int pa; // Non-standard member
int pb; // Non-standard member
} struct SXyz {
int a; // Standard member
int b; // Standard member
int c; // Standard member
};
// Usage in code:
SXyz* p = new SXyz; // Allocates a struct with only a, b, c members
SXyz* p = prenew SXyz; // Allocates a struct with all members (pa, pb, a, b, c)
// Member access:
p->pa = -2; // Access at offset -8 (can be accessed even if new was used)
p->pb = -1; // Access at offset -4 (can be accessed even if new was used)
p->a = 0; // Access at offset 0
p->b = 1; // Access at offset 4
p->c = 2; // Access at offset 8
// Total sizeof() is 12 (for members a, b, c) as the pre block members are not
// included in the size operation. However, if you use presizeof() you will see
// its size reporting the full 20 bytes.
// Note: If accessing pre members on a non-pre block, the results are invalid
In this way, negative members can be accessed at any time, but are not part of the actual structure in use or in size. To use the full member, use presizeof(), prenew, and predelete.