Setting array length to 0 discards reserved allocation?
Andrew Godfrey via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 1 00:51:31 PDT 2014
Going through other .dd files, I found an error in expression.dd.
It says "For static or dynamic arrays, identity is defined as
referring
to the same array elements and the same number of elements."
Well, in fact:
unittest {
// expression.dd says that equality AND IDENTITY compare
elements and sizes, for both "static and dynamic arrays". Gaah!
int[] a = new int[3];
int[] b = new int[3];
assert(a == b);
assert(a !is b); // Nope! The doc is wrong!
// So then:
b = a;
assert(b is a); // Now b points to a, and 'is' does what I'd
expect.
// But evidently it's because it compared the array
references - not
// the elements and sizes!
}
I would NOT recommend updating the compiler to match what the doc
says.
The current behavior is consistent with how assignment to an
array reference behaves.
More information about the Digitalmars-d
mailing list