Skip to content

Instantly share code, notes, and snippets.

@graymalkin
Created March 27, 2018 16:32
Show Gist options
  • Save graymalkin/e2274691659cc9f0e56fbb657bf99c48 to your computer and use it in GitHub Desktop.
Save graymalkin/e2274691659cc9f0e56fbb657bf99c48 to your computer and use it in GitHub Desktop.
// gcc -Wall -std=gnu11 main.c -o main
#include <stdio.h>
#include <stdlib.h>
typedef void callback_t(void);
void test(void (*)(void));
void myFun(void *);
int main(int argc, char * argv[]) {
int * x = malloc(sizeof(int));
*x = 42;
void myCallback(void) {
myFun((void*) x);
}
test(&myCallback);
}
void myFun(void* data) {
int num = * ((int*)data);
printf("Number: %d\n", num);
}
void test(void (*f)(void)) {
f();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment