Is it possible to do something like this?:
struct S {
int length;
char data[100];
}
class C {
uint8_t buffer[10];
S& s = buffer[0];
}
If I use pointer it compiles, but working with reference would be more convenient:
class C {
uint8_t buffer[10];
S* s = (S*)buffer;
}
In case you are wondering why one would do something like that, I have a struct similar to S above that is used to send and parse various data packets. Some actual packets have known limited lengths, so it does not make sense to allocate more space than necessary for them, by declaring member as simple S.