Created
March 27, 2018 16:32
-
-
Save graymalkin/e2274691659cc9f0e56fbb657bf99c48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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