Skip to content

Instantly share code, notes, and snippets.

@9re
Created December 24, 2011 06:25
Show Gist options
  • Save 9re/1516551 to your computer and use it in GitHub Desktop.
Save 9re/1516551 to your computer and use it in GitHub Desktop.
ugly type declaration without typedef
#include <stdio.h>
char * const func(int a, int b) {
static char * const str = "Yeah!";
printf("%s a: %d, b: %d\n", __func__, a, b);
return str;
}
char * const (*func_getter(int a))(int, int) {
printf("%s a: %d\n", __func__, a);
return &func;
}
int main(int argc, char **argv) {
char * const (*(*ptr_func_getter)(int))(int, int) = &func_getter;
char * const (*ptr_func_arr[3])(int, int) = {
ptr_func_getter(4),
ptr_func_getter(5),
ptr_func_getter(6)
};
for (int i = 0; i < 3; ++i) {
char * const (*p)(int, int) = ptr_func_arr[i];
p(3, i);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment