Skip to content

Instantly share code, notes, and snippets.

@irondoge
irondoge / macro.cpp
Created December 1, 2016 17:39
Recursive variadic C/C++ macro. [compilation: gcc -std=c++11 macro.cpp]
#include <stdio.h>
#define PRINT(...) CAT(CT(__VA_ARGS__))(__VA_ARGS__)
#define CAT(N) DOG(N)
#define DOG(N) PRINT ## N
/* max supported args is 5 for now */
#define CT(...) VALS(__VA_ARGS__, 5, 4, 3, 2, 1)
#define VALS(N1, N2, N3, N4, N5, N, ...) N