Having worked a few weeks now with #C #code that uses __attribute__ (cleanup) , I am disappointed to say that it's an insignificant improvement.

Why?

Because you need to remember to annotate every variable, and sometimes cleanup is not what you want, leading to double-free.
At least the freeing is declared next to the variable, so that's nice.

But this still sucks compared to #RAII imposed on the type, where you don't need to remember.

#programming #coding #memory #safety

Follow

@dcz I'd think that having to use 'cleanup' too much would be indicative of some very poorly structured code, but sometimes one is forced to do that. Most of the C code I've seen in industry is poorly structured, and it appears to be getting worse. Good practice is driven by , and .

Sign in to participate in the conversation
Librem Social

Librem Social is an opt-in public network. Messages are shared under Creative Commons BY-SA 4.0 license terms. Policy.

Stay safe. Please abide by our code of conduct.

(Source code)

image/svg+xml Librem Chat image/svg+xml