Compiler dmd_2.068.0-0_amd64.deb on Ubuntu 12.04 Linux:
auto lookup = [ one:1, two:2 ];
The dmd error:
Error: non-constant expression [one:1, two:2]
Why doesn't it compile?
As a workaround I could do the assignment one element at a time
in a loop. It would be uglier though.
Hello,
Why dmd cannot inference the type of 'arr' in my_func() parameter?
test.d:
import std.stdio;
void my_func(auto arr)
{
writeln(arr);
}
void main()
{
auto arr = new int[5];
arr = [1, 2, 3, 4, 5];
my_func(arr);
}
dmd test.d
test.d(3): Error: undefined identifier arr
Adel
import std.stdio;
void main()
{
ubyte[] a1 = new ubyte[65];
ubyte[65] a2;
writeln(a1.sizeof = , a1.sizeof); // prints 16
writeln(a2.sizeof = , a2.sizeof); // prints 65
}
Why a1.sizeof is 16?
ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes.
auto a2 = new ubyte[5]; // Fine. Five 0 bytes.
Now, let's say, I want to allocate an array of a size, derived at
run time, and initialize it to some non-zero value at the same
time. What would be the shortest way of doing it?