Dynamically Sized Structs
Dicebot
public at dicebot.lv
Thu Apr 17 11:22:23 PDT 2014
On Thursday, 17 April 2014 at 18:17:59 UTC, Kagamin wrote:
> State* pointer in sokoban example is a perfect 1 indirection.
It is not related to actual "dynamic struct" thing, which is why
I have highlighted the line to look at. Minimal example is this:
struct Dynamic
{
size_t length;
int[0] payload;
}
void main()
{
const length = 42;
Dynamic* entity = alloca(Dynamic.sizeof + int.sizeof*length);
entity.length = length;
// pointer to same stack space so not really an indirection
entity.payload[5] = 43;
}
More information about the Digitalmars-d-learn
mailing list