3 ms·
That link seems to be broken? Nothing opens when I click it.
by gnulinux 7y ago
That link seems to be broken? Nothing opens when I click it.
- saagarjha 7y agoWorks fine for me. It's using __attribute__((cleanup)) to call a function that calls the block you give it.
- shakna 7y agoIt's a short article, and worth reading if you can work out why the Wayback Machine isn't working for you. The magic is basically: static inline void defer_cleanup(void (^*b)(void)) { (*b)(); } #define defer_merge(a,b) a##b #define defer_varname(a) defer_merge(defer_scopevar_, a) #define defer __attribute__((cleanup(defer_cleanup))) void (^defer_varname(__COUNTER__))(void) = Which let's you do: FILE *a = fopen ("a.txt", "r"); if (!a) return EXIT_FAILURE; defer { fclose (a); }; It uses cleanup and blocks, both of which are extensions. There may also be some strangeness with the way blocks hold memory. (Block references become const copies).
- Twirrim 7y agohttp://fdiv.net/2015/10/08/emulating-defer-c-clang-or-gccblocks http://fdiv.net/2015/10/08/emulating-defer-c-clang-or-gccblo... The original link works.
- shakna 7y agoThe original link pops up with a HTTP basic authentication request for me, hence the use of archive.