default initialization of char arrays

monkyyy crazymonkyyy at gmail.com
Wed Oct 15 15:22:14 UTC 2025


On Wednesday, 15 October 2025 at 11:51:05 UTC, Quirin Schroll 
wrote:
> On Monday, 8 September 2025 at 15:42:27 UTC, Walter Bright 
> wrote:
>> […]
>>
>> A `char` default initializes to `0xFF`. The programmer wanted 
>> to default initialize the array of char to `0`, and so used 
>> `[0]` to initialize it. This resulted in 
>> `[0,255,255,255,255,255,255,255,255,255]`. He asked how to 
>> default initialize it to `0` without having to tediously 
>> enumerate the `0` for each element in the initializer.
>
> Please make this footgun an error. The compiler can tell you in 
> the error message to use `= x` instead of `= [x]`, since it’s a 
> common pattern in C. My best bet is that no-one uses `[0]` 
> being in fact `[0, 0xFF …]` intentionally.

Only because of the insane idea of intentionally invalid 
initialization

`int[N]=[1,2,3]` being trailing zeros makes more sense


More information about the Digitalmars-d mailing list