D Language Foundation September 2025 Monthly Meeting Summary - static array missing elements

Nick Treleaven nick at geany.org
Sun Mar 15 19:29:52 UTC 2026


On Thursday, 12 March 2026 at 09:30:43 UTC, Mike Parker wrote:
> The D Language Foundation's September 2025 monthly meeting took 
> place on Friday the 12th and lasted about an hour and 
> thirty-five minutes.

Thanks for this!

> Walter proposed two possible syntaxes in the chat:
>
> ```d
> int[6] a = [4,2,8,...];
> int[6] a = [4,2,8,3...];
> ```
>
> The first one initializes the array with `4, 2, 8`, then the 
> remaining elements are default-initialized. In the second one, 
> the remaining elements are initialized with `3`. If someone 
> wanted to write a DIP for that, he saw no reason why it 
> shouldn't be done. Then we could deprecate mismatched 
> initializer length without losing that syntax.
>
> Rikki thought the expression should go after the `...`, 
> otherwise it would be parsed as a float or something nasty. 
> Walter thought it was processed eagerly, so it should be fine.
>
> Nicholas understood why Walter wanted two syntaxes for that, 
> but he suggested using indices for one and not the other. The 
> problem was that `3,...` and `3...` looked very similar. That 
> was going to be typo-prone and difficult to read. I said that 
> without my glasses, I was struggling to see the difference. I 
> hadn't noticed the comma after the `8`.
>
> Walter said that if someone wanted to write a DIP for it, we 
> could debate syntax options then. He didn't think we'd solve it 
> there.

I'd like to write a DIP for this. Something like `... = 3` could 
work and would be visually distinct.

> Martin said he'd never had a need for anything like that. He 
> asked whether Walter had ever needed to explicitly initialize 
> the first few elements of an array, then all the rest with the 
> default or the last element. Walter said he had seen it. People 
> sometimes initialized arrays with a couple thousand elements 
> and only populated the beginning. It might not be great 
> practice, but there was a reason C was done that way.
>
> Dennis had sent him an error case where somebody converted a 
> `char` array from C, and C default-initialized to `0`, while D 
> default-initialized to `FF`, producing a different result. That 
> example made it clear to him that we needed a way to specify 
> what the remaining default initializer was.

If we add an error for missing elements, the compiler could 
actually add a supplemental message saying to use `... = 0` if 
the declaration is used as a zero-terminated string, or when 
porting C code with an element type that has a non-zero init 
(floats).


More information about the Digitalmars-d-announce mailing list