Skip to content

Instantly share code, notes, and snippets.

@o11c
Created December 1, 2017 02:06
Show Gist options
  • Save o11c/378bc979a82d601fb58bcbd93a80a988 to your computer and use it in GitHub Desktop.
Save o11c/378bc979a82d601fb58bcbd93a80a988 to your computer and use it in GitHub Desktop.
#define REALLY_JOIN(a, b) a##b
#define JOIN(a, b) REALLY_JOIN(a, b)
#define ARG_16(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, ...) a15
#define COUNT(...) ARG_16(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#define FOO(...) JOIN(FOO_, COUNT(__VA_ARGS__))(__VA_ARGS__)
#include <stdio.h>
void FOO_1(int x)
{
printf("FOO_1(%d)\n", x);
}
void FOO_2(int x, int y)
{
printf("FOO_2(%d, %d)\n", x, y);
}
void FOO_3(int x, int y, int z)
{
printf("FOO_3(%d, %d, %d)\n", x, y, z);
}
int main()
{
FOO(1);
FOO(1, 2);
FOO(1, 2, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment