Created
January 15, 2011 05:15
-
-
Save saml/780715 to your computer and use it in GitHub Desktop.
function pointer typedef macro
This file contains 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
/* | |
gcc -ansi -pedantic -Wall -Wextra -std=c99 ftypedef.c | |
*/ | |
#include <stdio.h> | |
#define FTypedef(ReturnType, Name, ...) typedef ReturnType (*Name)(__VA_ARGS__) | |
void foo(int i, char *str) { | |
printf("%d - %s\n", i, str); | |
} | |
int main() { | |
FTypedef(void, Function, int i, char *str); | |
FTypedef(int, Fun, char const*, ...); | |
Function f = &foo; | |
Fun ff = &printf; | |
f(1, "hello world"); | |
ff("hello, %s\n", "your name"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment