On Friday, 4 August 2017 at 17:27:52 UTC, Timon Gehr wrote:
In D, the foreach loop variable is a distinct declaration for each loop iteration, while in C#, the same loop variable is repeatedly reassigned. In C#, the issue is bad language design, while in D, the issue is a buggy compiler implementation leading to memory corruption.
[ ... ]
It's reasonable to assume that the D compiler uses the same memory location for all of the distinct variables. This is a dangling pointer bug, if you wish. Both of your examples should print "0 1 2 3 4".
[ ... ]

3) heap allocate a chunk of space for each captured scope (as in lisp and C#).

The way to go is 3). 1) is bad, because it completely prevents closures from being escaped, 2) is bad because it does not allow sharing of closure memory.

Thanks for you insight Timon.
Would you mind writing an ER. (enhancment request) for that.
And a small spec-like proto-DIP ?

I'd love to adopt that behavior for newCTFE where it is actually the more straightforward way. (in light of the constraints newCTFEs architecture has)

Reply via email to