D2 full closure?
Walter Bright
newshound1 at digitalmars.com
Tue Jul 15 15:40:30 PDT 2008
BCS wrote:
> Oh crud, I read it wrong.
>
> OTOH that problem is even worse than the issue I was thinking of:
>
> is this valid?
Yes.
> does it generate a different heap frame for each time
> through the loop?
All that happens is the stack frame is put on the heap. It doesn't
allocate new heap frames in a loop.
>
> alias void delegate() Runner;
>
> void main(){
> Runner[] runner;
> int i;
> for(i = 0; i < 3; i++ ){
> const int ci = i;
> runners ~= delegate(){ writefln( "run with ci=%d, i=%d", ci, i ); }
> }
> foreach( runner; runners ){
> runner();
> }
> }
>
>
> is this valid?
Yes.
>
> void main()
> {
> Runner a;
> {
> int i = 5;
> a = {i++;}
> }
>
> {
> int j = 6;
> a();
> assert(j==6);
> }
> }
>
>
More information about the Digitalmars-d
mailing list