default initialization of char arrays

Quirin Schroll qs.il.paperinik at gmail.com
Wed Oct 15 11:51:05 UTC 2025


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.


More information about the Digitalmars-d mailing list