Does D actually support flexible array members?

Paul Backus snarwin at gmail.com
Tue Sep 6 13:59:17 UTC 2022


On Tuesday, 6 September 2022 at 11:51:35 UTC, IchorDev wrote:
> On Thursday, 18 August 2022 at 11:25:22 UTC, Paul Backus wrote:
>>
>> I think the closest way to approximate this in D is to use a 
>> zero-length static array:
>>
>> ```d
>> struct ArenaChunk {
>>     size_t size;
>>     ArenaChunk* next;
>>     char[0] memory;
>> }
>> ```
>
> Would Nullable be a good option as well? 
> [https://dlang.org/phobos/std_typecons.html#Nullable](https://dlang.org/phobos/std_typecons.html#Nullable)

For a dynamically-sized struct? No, it would not; Nullable has a 
fixed size.


More information about the Digitalmars-d-learn mailing list