Skip to content

Instantly share code, notes, and snippets.

@Mons
Created February 19, 2016 21:18
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 Mons/5c646d3a4af425465a68 to your computer and use it in GitHub Desktop.
Save Mons/5c646d3a4af425465a68 to your computer and use it in GitHub Desktop.
C DEFER
// (c) Roman Tokarev
#ifndef _DEFER_H_
#define _DEFER_H_
#define CONCAT(a_, b_) a_ ## b_
#define CONCAT2(a_, b_) CONCAT(a_, b_)
#define UNIQUE_TOKEN(var_) CONCAT2(var_, __LINE__)
#define DEFER \
auto void UNIQUE_TOKEN(defer_foo)(char *); \
__attribute__((unused, cleanup(UNIQUE_TOKEN(defer_foo)))) char UNIQUE_TOKEN(defer_var); \
void UNIQUE_TOKEN(defer_foo)(char *unused __attribute__((unused)))
#endif // _DEFER_H_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment