Skip to content

Instantly share code, notes, and snippets.

@bvk
Created January 22, 2016 22:27
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 bvk/88879332aeca41a7482c to your computer and use it in GitHub Desktop.
Save bvk/88879332aeca41a7482c to your computer and use it in GitHub Desktop.
Go like "defer" for C using GCC extensions
#define defer_(x) do{}while(0); \
auto void _dtor1_##x(); \
auto void _dtor2_##x(); \
int __attribute__((cleanup(_dtor2_##x))) _dtorV_##x=69; \
void _dtor2_##x(){if(_dtorV_##x==42)return _dtor1_##x();};_dtorV_##x=42; \
void _dtor1_##x()
#define defer__(x) defer_(x)
#define defer defer__(__COUNTER__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment