October 01

On Wednesday, 1 October 2025 at 20:00:35 UTC, monkyyy wrote:

>

On Wednesday, 1 October 2025 at 18:09:27 UTC, Ogion wrote:

>

On Wednesday, 10 September 2025 at 23:35:29 UTC, JN wrote:

>

I feel like in such scenario a warning should be issued, or even compilation error, "static array initialization expects 10 values, only 1 provided". Sooner or later someone will hit the same issue again and spend hours debugging why the array doesn't get zeroed.

Yep, the syntax should be more explicit. Something like this:

float[10] x = [42, ...];   // [42, NaN, ..., NaN]
float[10] y = [1:42, ...]; // [NaN, 42, NaN, ..., NaN]

nah they just going to break it without a replacement

you can always create a mixin

October 01

On Wednesday, 1 October 2025 at 21:01:28 UTC, not you wrote:

>

On Wednesday, 1 October 2025 at 20:00:35 UTC, monkyyy wrote:

>

On Wednesday, 1 October 2025 at 18:09:27 UTC, Ogion wrote:

>

On Wednesday, 10 September 2025 at 23:35:29 UTC, JN wrote:

>

I feel like in such scenario a warning should be issued, or even compilation error, "static array initialization expects 10 values, only 1 provided". Sooner or later someone will hit the same issue again and spend hours debugging why the array doesn't get zeroed.

Yep, the syntax should be more explicit. Something like this:

float[10] x = [42, ...];   // [42, NaN, ..., NaN]
float[10] y = [1:42, ...]; // [NaN, 42, NaN, ..., NaN]

nah they just going to break it without a replacement

you can always create a mixin

replacing 1 line of code with 30 isnt great

October 01

On Wednesday, 1 October 2025 at 21:28:00 UTC, monkyyy wrote:

>

On Wednesday, 1 October 2025 at 21:01:28 UTC, not you wrote:

>

On Wednesday, 1 October 2025 at 20:00:35 UTC, monkyyy wrote:

>

On Wednesday, 1 October 2025 at 18:09:27 UTC, Ogion wrote:

>

On Wednesday, 10 September 2025 at 23:35:29 UTC, JN wrote:

>

[...]

Yep, the syntax should be more explicit. Something like this:

float[10] x = [42, ...];   // [42, NaN, ..., NaN]
float[10] y = [1:42, ...]; // [NaN, 42, NaN, ..., NaN]

nah they just going to break it without a replacement

you can always create a mixin

replacing 1 line of code with 30 isnt great

how often do you need this 'feature'? can you show a real world usecase?

October 02

On Monday, 8 September 2025 at 15:44:27 UTC, Walter Bright wrote:

>

https://dlang.org/spec/arrays.html#static-init-static

I've been programming in D for many years because of such wonderful language features. But, in my opinion, we need to focus on stabilizing and fixing what we already have. Speaking of static arrays, I’d like to remind that we've had a long-standing bug with a segmentation fault: type inference doesn't work for a static array of type real[1].

void main() {
    import std.stdio : writeln;
    real[1] arr = 0;
    writeln(arr); // SEGFAULT
}

https://github.com/dlang/dmd/issues/21323

October 02

Correction: array output to screen does not work.

October 15

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.

October 15

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

October 15

On Monday, 8 September 2025 at 15:42:27 UTC, Walter Bright wrote:

>

This came up in an email exchange. Consider:

import core.stdc.stdio;

__gshared char[10] xxx = [0]; // initialize xxx to all zeros

void main()
{
    foreach (c; xxx)
        printf("%d\n", c);
}

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.

The answer is:

__gshared char[10] xxx = 0;

At least the compiler is smart enough to know that the following is an error.

void main()
{
	char[10] xxx = [0];
}
October 22

On Wednesday, 15 October 2025 at 15:22:14 UTC, monkyyy wrote:

>

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

D not copying that C behavior is sane. But what makes it bad is that D still allows you to not define all elements of the array, and implicitly initiliszes them in a non intuative way.

Here is what I'd change it to:

float[10] a = [42];   // This should be a error.
float[10] b = [0:42, 5: 3.14]; // This also should be an error.
float[10] c = [0..$: 0]; // Sets all to zero.
float[10] d = [42, 1..$: 0]; // First element is 42, everything else is zero.
float[10] e = [1..$: 42]; // Error, first element is not defined.

This should be familiar due to the slicing syntax D already has.

October 22

On Wednesday, 22 October 2025 at 16:35:47 UTC, 6622 wrote:

>

On Wednesday, 15 October 2025 at 15:22:14 UTC, monkyyy wrote:

>

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

D not copying that C behavior is sane. But what makes it bad is that D still allows you to not define all elements of the array, and implicitly initiliszes them in a non intuative way.

Here is what I'd change it to:

float[10] a = [42];   // This should be a error.
float[10] b = [0:42, 5: 3.14]; // This also should be an error.
float[10] c = [0..$: 0]; // Sets all to zero.
float[10] d = [42, 1..$: 0]; // First element is 42, everything else is zero.
float[10] e = [1..$: 42]; // Error, first element is not defined.

This should be familiar due to the slicing syntax D already has.

float[10] b = [0:42, 5: 3.14, $:13.37];//[0,13.37,13.37,13.37,13.37,3.14,13.37...