I’d like to access the struct parameter from within the size function/expression, but have found no way to do so. The struct’s parameter is available somewhere, even before the struct body is executed, since that body needs its value to set up the variables etc. However, it seems that it’s inaccessible from within size.
I have the following struct:
typedef struct (int L) {
uint8 value[L];
} Misc;
I need to access its parameter to calculate its size.
I can access the parametrized size of the value field in the read function:
// Works
typedef struct (int L) {
uint8 value[L];
} Misc <read=dump(this.value, sizeof(this.value))>;
But I can’t access it in the size function, as expected, since nothing inside the struct definition has executed yet.
// Doesn't work
typedef struct (int L) {
uint8 value[L];
} Misc <size=(sizeof(this.value))>;
typedef struct (int L) {
uint8 value[L];
} Misc <size=this.L>;
It raises ERROR: Variable 'value'/'L' is not a member of the structure.
Trying to use L straightforwardly also fails:
// Doesn't work
typedef struct (int L) {
uint8 value[L];
} Misc <size=L>;
It raises ERROR: Variable 'L' is undefined.
Using a local buffer variable doesn’t work - as expected, since nothing inside of the struct has executed yet when size is called:
// Doesn't work either
typedef struct (int L) {
uint8 value[L];
local int len=L;
} Misc <size=this.len>;
However, there’s no way to access it from the template, without loading some custom DLLs to sniff around 010’s process heap to extract it.