Skip to content

Instantly share code, notes, and snippets.

@apfohl
Created September 15, 2015 18:27
Show Gist options
  • Save apfohl/6e25587350fbb111bcaf to your computer and use it in GitHub Desktop.
Save apfohl/6e25587350fbb111bcaf to your computer and use it in GitHub Desktop.
C Function Pointer passing
#include <stdio.h>
union env {
void (*func)();
};
void foo(int a, int b)
{
printf("%d\n", a + b);
}
int main(void)
{
void *temp = NULL;
union env env;
env.func = foo;
temp = &env;
((union env *)temp)->func(1, 2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment