4 ms·
I like your C-like syntax better. But I don't think there's any need to differentiate between different captures. Capture by value is enough because what do yo
by yason 5y ago
I like your C-like syntax better.
But I don't think there's any need to differentiate between different captures. Capture by value is enough because what do you need in C if you need a reference? Capture the value of the pointer.
{
void *chunk = malloc(x);
defer (chunk, void **reference = &chunk) { ... }
...
}
This would allow you to operate on the value both from the defer declaration time and defer execution time, whichever it is that you need.
- nrclark 5y agoThat's an interesting point, and very C-like. You're right that capture-by-value can emulate capture-by-reference. Capture-by-value does have a weakness though, in that it requires allocation (whether stack or heap). Capture-by-reference doesn't have any storage overhead. In my example, I suggested having both. But if we had to pick only one, capture-by-value would be the one to use.