Live data from Hacker News

C: Simple Defer, Ready to Use

gustedt.wordpress.com

1–10 of 157 posts

Re: C: Simple Defer, Ready to Use

#4
Do defers get processed if an exception is thrown? I know C doesn’t have exceptions, but real world C code often interacts with C++ code. So it is necessary imo to define that interaction.

In C++ we have something pretty similar already in the form of Folly ScopeGuard (SCOPE_EXIT {}).

Re: C: Simple Defer, Ready to Use

#6
post #5

This should have been in C ages ago, but better late than never!

This isn't new. The only C23 feature this article uses is the attribute syntax, but you could just use `__attribute((cleanup(F)))` instead.

Tis a joke my friend.

Re: C: Simple Defer, Ready to Use

#7
post #4

Do defers get processed if an exception is thrown? I know C doesn’t have exceptions, but real world C code often interacts with C++ code. So it is necessary imo to define that interaction. In C++ we have something pretty similar already in the form of Folly ScopeGuard (SCOPE_EXIT {}).

GCC has the __cleanup__ attribute which works in conjunction with exceptions in C to provide an RAII mechanism.

Re: C: Simple Defer, Ready to Use

#8
post #5

Earlier quoted context omitted.

This isn't new. The only C23 feature this article uses is the attribute syntax, but you could just use `__attribute((cleanup(F)))` instead.

Tis a joke my friend.

i like how the contraction it’s and abbreviation T’is are anagrams
Post reply on HN