Dynamically Sized Structs
bearophile
bearophileHUGS at lycos.com
Thu Apr 17 02:30:45 PDT 2014
Dicebot:
> Just in case, the key line to pay attention to in that example
> is this one:
>
> CellIndex[0] c_;
When you define dynamically sized structs it's also a good idea
to wrap the items access with some kind of get/set functions, to
make the code less bug-prone (and sometimes there is also a
length available somewhere that those functions can use to verify
the bounds in non-release builds).
> It is a commonly used C idiom for dynamically sized structures
> that D also supports.
D supports zero length fixed size arrays for this usage too. And
recently their .ptr was changed from null to their start addreess
to improve this usage.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list