Created
May 8, 2014 20:00
-
-
Save brimston3/d033327435e2f537ce59 to your computer and use it in GitHub Desktop.
Selecting functions using C preprocessor symbol concatenation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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