Skip to content

Instantly share code, notes, and snippets.

@phausler
Created March 20, 2017 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phausler/affdf697165cfb36dd15c1ec95a2e4ad to your computer and use it in GitHub Desktop.
Save phausler/affdf697165cfb36dd15c1ec95a2e4ad to your computer and use it in GitHub Desktop.
Defer for c
__attribute__((used))
static inline void __deferred(void (^*b)(void)) { if (b) (*b)(); }
#define ___PASTE__(x, y) x ## y
#define __PASTE__(x, y) ___PASTE__(x, y)
#define defer(block) void (^__PASTE__(__cleanup, __COUNTER__))(void) __attribute__((cleanup(__deferred), unused)) = block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment