241
General Discussion / Struct "inheritance"
« on: June 24, 2018, 12:13:33 AM »
Taking a page from JAI, why not allow "struct includes":
All of this is resolved during compile time, so this would not work for example:
Code: [Select]
type MyData struct {
const char* name;
State status;
}
type MyDataExtended struct {
int32 foo;
MyData data @(inline);
ExtendedStatus extendedStatus;
}
MyDataExtended foobar;
// initialize foobar here
...
// Init done
Code: [Select]
printf("Value: %s\n", foobar.name) // Due to the @(inline) attribute.
func void MyData.parse(MyData* data) {
// ...
}
func void randomizeData(MyData* data) {
// ...
}
foobar.parse() // valid, equivalent to foobar.data.parse()
randomizeData(foobar) // valid, equivalent to randomizeData(foobar.data)
All of this is resolved during compile time, so this would not work for example:
Code: [Select]
func void funky(void *data) {
randomizeData(cast<MyData>(data));
}
funky(cast<void>(foobar)); // Will not work as expected.
However, the code WOULD behave nicely if MyDataExtended did not start with the i32 field...