2 ms·
Here's a thought: some languages have a defer statement that runs when the function is exited. This allows for cleanup code to run even with early return. Perha
by andai 5y ago
Here's a thought: some languages have a defer statement that runs when the function is exited. This allows for cleanup code to run even with early return. Perhaps a block-level defer could be useful:
int i = 0;
while (i < 10) {
defer i++;
// ...
continue;
// ...
}
- AlbertoGP 5y agoIf someone wants to play with this idea, I made a pre-processor that translates that into standard C, inserting the deferred statements at each exit point (break, continue, goto, return, end of block): https://news.ycombinator.com/item?id=28166125 https://news.ycombinator.com/item?id=28166125 https://sentido-labs.com/en/library/cedro/202106171400/#deferred-resource-release https://sentido-labs.com/en/library/cedro/202106171400/#defe...
- andai 5y agoHahah, what are the odds! Thanks for sharing, I will take a look.