convert static arrays to dynamic arrays and return, have wrong data.
AlanThinker via Digitalmars-d
digitalmars-d at puremagic.com
Sun Nov 9 00:29:58 PST 2014
It seems that, D's array is strange,
It can implicit convert static arrays to dynamic arrays no error
and no warning.
But when I return the converted arrays out the function.
Outside function will get some wrong data.
It may very easily cause some bug because no error when convert
static arrays to dynamic arrays.
CODE:
import std.stdio;
void main()
{
auto a1 = test11();
auto a2 = test22();
assert(a1==a2);
writeln(a1);
writeln(a2);
getchar();
}
int[3] test1()
{
int[3] arr;
arr[0]=1;
arr[1]=2;
arr[2]=3;
return arr;
}
int[] test11()
{
return test1();
}
int[3] test2()
{
int[3] arr;
arr[0]=1;
arr[1]=2;
arr[2]=3;
return arr;
}
int[] test22()
{
return test2();
}
More information about the Digitalmars-d
mailing list