Skip to content

Instantly share code, notes, and snippets.

@brimston3
Created May 8, 2014 20:00
Show Gist options
  • Save brimston3/d033327435e2f537ce59 to your computer and use it in GitHub Desktop.
Save brimston3/d033327435e2f537ce59 to your computer and use it in GitHub Desktop.
Selecting functions using C preprocessor symbol concatenation.
#include <stdio.h>
#include <stdarg.h>
void f1() {
printf("a\n");
}
void f2() {
printf("b\n");
}
void f3(const char * fmt, ...) {
va_list vaList;
va_start(vaList, fmt);
vfprintf(stderr, fmt, vaList);
va_end(vaList);
}
#define PICK(n, ...) f##n (__VA_ARGS__)
int main() {
PICK(1);
PICK(2);
PICK(1);
PICK(3,"Massive %s\n", "d*!@ery");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment