Sujet : Re: Opinions on `defer`?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 08. Jan 2025, 13:53:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vllsfj$2pfgn$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 06/01/2025 21:53, Kaz Kylheku wrote:
On 2025-01-07, Alexis <flexibeast@gmail.com> wrote:
>
Hi all,
>
"Modern C" author Jens Gustedt has been posting on his blog about a
proposed `defer` feature (as provided by e.g. Zig and Go), the most
recent being:
>
https://gustedt.wordpress.com/2025/01/06/simple-defer-ready-to-use/
>
What do people here think about having such a feature in C?
I'm okay if a self-hosted implementation can be demonstrated, which
defers itself to a future discussion.
There is another proposal
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3199.htmThat is implemented in cake.
http://thradams.com/cake/playground.htmlDefer can be useful in some cases, reducing code size, facilitating maintenance, and centralizing resource release information in one place.
In Cake, ownership qualifiers ensure resources are correctly released, making it safer than defer and C++ RAII. You don't need to remember to free resources, as the compiler will warn you if necessary. In this scenario, defer may still be useful, not for safety, but to reduce the amount of visible code.