3 ms·
There is a proposal to get this using the "defer" keyword into either the next C revision or the one after that[1]. [1]: https://www.open-std.org/jtc1/sc22/wg1
by ainar-g 2y ago
There is a proposal to get this using the "defer" keyword into either the next C revision or the one after that[1].
[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3199.htm https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3199.htm.
- tredre3 2y agoThat would be sublime! Defer is something I've been wanting in C for 20 years. It makes resource management clear, easy to reason about, and concise.
- Dwedit 2y agoThat looks a lot like what Zig does. One problem with the proposed defer there is that it has no way to interact with stack unwinding, which is part of the platform ABIs for handling exceptions. Maybe some alternative syntax, such as "defer_finally" could make the defer block act as both a regular defer block, and also explicitly add that block to the stack unwinding chain.
- deleted 2y ago[deleted]
- cozzyd 2y agoyou can implement a crappy version of defer with GNU extensions, I think? https://gist.github.com/cozzyd/a9eb2ddb9c8785ad5c60e3280b0babf7#file-cleanup-c-L66 https://gist.github.com/cozzyd/a9eb2ddb9c8785ad5c60e3280b0ba...
- kazinator 2y agoIt seems that whenever ISO C invent their own imitation of some GNU feature, in order to foist onto other compilers, they fuck it up first. VLA's, inline, variadic macros, ... More recently, they gaffed by making alignment specification not a type attribute but, get this, a storage class specifier. Ouch!