Created
November 10, 2017 16:53
-
-
Save b4284/5cc5298b67c9fee0447dff9d17180493 to your computer and use it in GitHub Desktop.
Function Pointer for Compatibility?
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
#include "lib.h" | |
int give_me_callback(Callback callback) { | |
return callback(1, 2.2, "3"); | |
} |
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
typedef int Callback(int, double, const char *); | |
int give_me_callback(Callback callback); |
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
#include "lib.h" | |
// Defines a callback but incompatible with lib's callback type. | |
int callback_4args(int a, double b, const char *c, void *d) | |
{ | |
return a; | |
} | |
int main() { | |
return give_me_callback(callback_4args); // Warning, but compiles and runs. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment