News for hackers. Stuff that matters.
Re:Braiding the spaghetti: implementing defer in the preproc... by pif on Monday September 16, 2024 @04:59AM (#41554126)
If you want to use RAII in C, just use the "cleanup" attribute of gcc.

https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attribute...

Re:Braiding the spaghetti: implementing defer in the preproc... by wffurr on Monday September 16, 2024 @06:52AM (#41554755)
*in non portable non standard C
Re:Braiding the spaghetti: implementing defer in the preproc... by gobblegobble2 on Monday September 16, 2024 @07:33AM (#41554990)
Supported by both gcc and clang, so portable enough for most people. I also like glib's cleanup attribute wrappers: https://docs.gtk.org/glib/auto-cleanup.html.
Re:Braiding the spaghetti: implementing defer in the preproc... by wyldfire on Monday September 16, 2024 @08:27AM (#41555364)
It is non portable, that's true. But defer [1] is at least undergoing discussions w/the standard committee. Didn't make it into C23 but maybe next time.

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2895.htm

Re:Braiding the spaghetti: implementing defer in the preproc... by gustedt on Monday September 16, 2024 @10:16AM (#41556316)
That's not very practical if you have several operations to perform, you'd have to create a specialized function each time. So no, that extension is not an alternative to designing a new flow control feature. (And it is not new, other languages have it already.)