4 ms·
I usually use the single-exit-point idiom with gotos to handle cleanup. I now wonder if there is a compiler that helps you enforce that so you don’t randomly st
by david2ndaccount 5y ago
I usually use the single-exit-point idiom with gotos to handle cleanup. I now wonder if there is a compiler that helps you enforce that so you don’t randomly stick a return in the middle of your function.
Anyway, this would be great to have in C as it would simplify how resources are handled.
- 95014_refugee 5y agoYou can use the cleanup attribute and a flag to detect early exit.
- loeg 5y agoYou can use the non-standard, but typically implemented, cleanup attribute today for function-scoped cleanup. I don’t know if compilers inline this kind of “destructor”. It works well — I’ve seen it used successfully at multiple employers.