Hello,
I got stuck with a weird array setting behaviour and I need help.
Just have a look at the example.
OS: Win 8.1 Pro
DMD: v2.071.0
Build-cmd: dmd main.d -ofconsole-app.exe -debug -unittest -g -wi
-m64
module dmain;
import std.stdio;
struct Vec {
float a;
}
void main(string[] args) {
Vec[] array = new Vec[4];
writeln("before: ", array); // prints [Vec(nan), Vec(nan),
Vec(nan), Vec(nan)]
array[] = Vec(24);
writeln("after: ", array); // prints [Vec(0), Vec(0), Vec(0),
Vec(0)]
}
Seems like slicing is broken in general. All the following
variations produce different results but they are all wrong.
array[] = Vec(24);
array[0 .. 1] = Vec(24);
array[0 .. $] = Vec(24);
It works as expected if I do one of the following things:
1. Get rid of -m64. If I compile with -m32 flag then I cannot
replicate the issue.
2. Changing the type of the Vec.a field from float to real, int,
uint, long, ulong fixes the issue. Double still causes the issues.
3. Adding new fields to the Vec struct.
3.1. Vec {float a, b; } still does not work but the result is
slightly different.
array[] = Vec(24, 5);
writeln("after: ", array); // [Vec(5, 0), Vec(5, 0), Vec(5, 0),
Vec(5, 0)]
3.2. Vec { float a, b, c; } works fine.
4. Using index operator: array[0] = Vec(24) works fine