[Issue 7564] Implicit conversion from static to dynamic array in loops
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 23 14:48:53 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7564
--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> 2012-02-23 14:48:52 PST ---
Temporary objects are destroyed ad the scope end, not statement end.
(In reply to comment #2)
> Ok, I understand, I was wrong. However on a related matter, I think that,
> import std.stdio;
> int[1] f(int i)
> {
> int[1] a = i;
> return a;
> }
> void main() {
> foreach (i; 0 .. 2) {
> writeln(f(i).ptr);
is same as:
auto tmp = f(i); writefln(tmp.ptr);
// tmp is destroyed at the end of foreach, so prints same address
> }
> writeln(f(0).ptr);
> writeln(f(1).ptr);
are same as:
auto tmp1 = f(i); writefln(tmp1.ptr);
auto tmp2 = f(i); writefln(tmp2.ptr);
// each temporaries has own memory, so prints different address
> }
>
> prints
> 7FFFF03A05E0
> 7FFFF03A05E0
> 7FFFF03A05E4
> 7FFFF03A05E8
>
> is a little bit strange, but I guess that just how it works.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list