4 ms·
The deferred resource cleanup is really the thing I wish the most was in C. I know that it's relatively un-"C-like", but having to make sure to clean up objects
by 0xTJ 5y ago
The deferred resource cleanup is really the thing I wish the most was in C. I know that it's relatively un-"C-like", but having to make sure to clean up objects on failure is one of the more annoying things that make my code messy. I like the `defer` paper and proposal linked in this article.
- shakna 5y agoLike the article mentioned, GCC, clang & icc all have the __cleanup__ attribute that can call a destructor for when a value moves out of scope. (And works pretty much how it would in C++). MVSC is really the only one missing it of the major compilers, but it doesn't implement half the actual standard anyways. __cleanup__ might be a C extension, but it's pretty widely supported. If you really wanted to have it be a code block instead of a function, in plain C, then you could possibly also use clang or GCC's lambda-ish extensions.