Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Last active June 1, 2017 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackjutsu/21b61e61b70b5f1893f1e1f2fdfee19b to your computer and use it in GitHub Desktop.
Save hackjutsu/21b61e61b70b5f1893f1e1f2fdfee19b to your computer and use it in GitHub Desktop.
[Function pointer example] Function #pointers are somewhat different than all other types because the syntax does not follow the pattern typedef <old type name> <new alias>; Instead, the new alias for the type appears in the middle between the return type (on the left) and the argument types (on the right).
typedef int (*MathFunc)(float, int);
int do_math(float arg1, int arg2) {
return arg2;
}
int call_a_func(MathFunc call_this) {
int output = call_this(5.5, 7);
return output;
}
int final_result = call_a_func(&do_math);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment