Skip to content

Instantly share code, notes, and snippets.

@b4284
Created November 10, 2017 16:53
Show Gist options
  • Save b4284/5cc5298b67c9fee0447dff9d17180493 to your computer and use it in GitHub Desktop.
Save b4284/5cc5298b67c9fee0447dff9d17180493 to your computer and use it in GitHub Desktop.
Function Pointer for Compatibility?
#include "lib.h"
int give_me_callback(Callback callback) {
return callback(1, 2.2, "3");
}
typedef int Callback(int, double, const char *);
int give_me_callback(Callback callback);
#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