2 ms·
This seems to be relevant: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-August/002670.html http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-August/00267... I
by limmeau 17y ago
This seems to be relevant: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-August/002670.html http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-August/00267...
In short: per default, you get copies of captured variables, but you can mark variables to be writable from blocks. In order to be able to call a block after the function call where it was created has ended, closures may be copied to the heap (with refcounting).
- onedognight 17y agoThe syntax for this is quite nice. call_me(^int (int x, int y) { return x + y; }); I like it quite a bit better than the proposed c++ lambda syntax. [](int x, int y) -> int { return x + y; } The ^ is very ananogous to *. You could declare the above function call_me() with something like this void call_me(int (^fun)(int x, int y)) { fun(fun(4,5), fun(3,6)); } which is quite "C like".