Skip to content

Instantly share code, notes, and snippets.

@darkfall
Created October 22, 2012 00:04
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 darkfall/3929023 to your computer and use it in GitHub Desktop.
Save darkfall/3929023 to your computer and use it in GitHub Desktop.
ukn static run code/call func
#define UKN_STATIC_RUN_CODE_I(name, code) \
namespace { \
static struct name { \
name() { \
code; \
} \
} UKN_JOIN(g_, name); \
}
#define UKN_STATIC_RUN_CODE(code) \
UKN_STATIC_RUN_CODE_I(UKN_UNIQUE_NAME(UKN_static_), code)
#define UKN_STATIC_CALL_FUNC_I(name, FN) \
namespace { \
static struct name { \
name() { \
static int counter = 0; \
if(counter++ > 0) return; \
FN(); \
} \
} g_##name; \
}
#define UKN_STATIC_CALL_FUNC(FN) \
UKN_STATIC_CALL_FUNC_I(UKN_static_init_##FN, FN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment