3 ms·
GCC has a similar extension for defering to end of scope, which is basically most of use cases(cleanup function is usually free or some destructor/sanity check
by FrozenVoid 6y ago
GCC has a similar extension for defering to end of scope,
which is basically most of use cases(cleanup function is usually free or some destructor/sanity check function).
https://echorand.me/site/notes/articles/c_cleanup/cleanup_attribute_c.html https://echorand.me/site/notes/articles/c_cleanup/cleanup_at...
- fanf2 6y agoIt’s annoying that the C committee does not standardize existing widely-used extensions that are supported by multiple compiler implementations.
- Asooka 6y agoThis is amazing, thanks! It's a bit different though - it executes a cleanup function when the variable goes out of scope, rather than a statement at the end of the enclosing guard block. It might be better though - it avoids some footguns that would be possible with a defer implementation.
- hsaliak 6y agoClang has this too. Libraries like Glib and software like Systemd use this mechanism. Standardizing it would be nice.