Skip to content

Instantly share code, notes, and snippets.

#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
@vaualbus
vaualbus / gist:c12ac212f9f7272b9cc76cdb1012d96b
Created August 12, 2019 10:25
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
@vaualbus
vaualbus / .cpp
Created September 9, 2018 16:17
This file replace the msvc CRT and allow you to init static variables and TLS
#if _CRT_DISABLE
extern "C" int _fltused = 0x9875;
#define WIN32_LEAN_AND_MEAN
#include <stdint.h>
#include <limits.h>
#include <windows.h>
//#include <Windows.h>
@vaualbus
vaualbus / CRT Replecament initialization
Created September 9, 2018 11:45
This code will initialize all the static variables and set up the basic TLS context to allow static variables in function to work
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define _CRTALLOC(x) __declspec(allocate(x))
#define nullptr 0
#define ArrayCount(Name) (sizeof(Name)/(sizeof(Name[0]))
void __acrt_iob_func()