Last active
December 27, 2015 00:59
-
-
Save DexterHaslem/7241702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| struct data_info | |
| { | |
| void (*done_callback) (int status); | |
| }; | |
| void done_handler(int status) | |
| { | |
| printf("done_handler: status=%d\n", status); | |
| } | |
| void process(struct data_info* thing, int status) | |
| { | |
| if (thing && thing->done_callback) | |
| thing->done_callback(status); | |
| } | |
| int main(int argc, char* argv[]) | |
| { | |
| struct data_info* test2; | |
| struct data_info test; | |
| test2 = malloc(sizeof(struct data_info)); | |
| test2->done_callback = done_handler; | |
| process(test2, 2); | |
| free(test2); | |
| /*test2 = NULL; left dangling! */ | |
| if (!test2 || !test2->done_callback) | |
| { | |
| puts("test2 bad, aborting"); | |
| return -1; | |
| } | |
| test.done_callback = test2->done_callback; | |
| if (!test.done_callback) | |
| puts("no callback, aborting"); | |
| process(&test, 1); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment