3 ms·
I've seen this implementation of defer a few times now. I really dislike calling this defer (like the keyword in Go) as the given code won't be executed on retu
by w4rh4wk5 2y ago
I've seen this implementation of defer a few times now. I really dislike calling this defer (like the keyword in Go) as the given code won't be executed on return.
- aartaka 2y agoScoping defer to a block is actually more useful and explicit than function-exclusive that Go does, so I consider that a feature.
- w4rh4wk5 2y agoNo no, I think you misunderstood my critic. Defer working on block-scope is fine; however, if I exit the block through a return (or break), the deferred function is not called. To my knowledge, you need a compiler extension to implement this in C (or use a C++ destructor).