Skip to content

Instantly share code, notes, and snippets.

@saml
Created January 15, 2011 05:15
Show Gist options
  • Save saml/780715 to your computer and use it in GitHub Desktop.
Save saml/780715 to your computer and use it in GitHub Desktop.
function pointer typedef macro
/*
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