Skip to content

Instantly share code, notes, and snippets.

@vaualbus
Created August 12, 2019 10:25
Show Gist options
  • Save vaualbus/c12ac212f9f7272b9cc76cdb1012d96b to your computer and use it in GitHub Desktop.
Save vaualbus/c12ac212f9f7272b9cc76cdb1012d96b to your computer and use it in GitHub Desktop.
C macro madness for __VA_ARGS__
#if COMPILER_MSVC
#define MSVC_HACK(FUNC, ARGS) FUNC ARGS
#define APPLY(FUNC, ...) MSVC_HACK(FUNC, (__VA_ARGS__))
#define VA_LENGTH(...) APPLY(VA_LENGTH_, 0, ## __VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#else
#define VA_LENGTH(...) VA_LENGTH_(0, ## __VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#endif
#define VA_LENGTH_(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, N, ...) N
Than for example
#define mglLog(Forma, ...) mglLog_(VA_LENGTH(__VA__ARGS__), __VA__ARGS__)
static void
mglLogì(s32 NumOfVaArgs, char *Format, ...)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment