Memory allocation in D (noob question)
Steven Schveighoffer
schveiguy at yahoo.com
Tue Dec 4 08:42:24 PST 2007
"Steven Schveighoffer" wrote
> Another reason why this is seems to be a bug and NOT a feature:
>
> string ab = "ab".idup;
> string a = ab[0..1];
> a ~= "c";
> writefln("ab = ",ab); // also outputs "ac"
>
> This changes an invariant string without compiler complaint!
more bugs :)
import std.stdio;
struct X
{
char[5] myArray;
int x;
}
void main()
{
X[] x = new X[2];
x[0].myArray[] = "hello";
char[] myslice = x[0].myArray[0..3];
writefln("%x %x %x", &x[0].x, &x[0].myArray[0], &myslice[0]);
myslice ~= "hithere";
writefln("%x %x %x", &x[0].x, &x[0].myArray[0], &myslice[0]);
writefln("%s %d", x[0].myArray, x[0].x);
}
output:
868FE8 868FE0 868FE0
868FE8 868FE0 868FE0
helhi 25970
-Steve
More information about the Digitalmars-d
mailing list