Skip to content

Instantly share code, notes, and snippets.

@droxer
Created February 28, 2015 13:49
Show Gist options
  • Select an option

  • Save droxer/30edcce84de162b24fbe to your computer and use it in GitHub Desktop.

Select an option

Save droxer/30edcce84de162b24fbe to your computer and use it in GitHub Desktop.
OO implementation by C.
#include <stdio.h>
struct greet_api
{
int (*say_hello)(char *name);
int (*say_goodbye)(void);
};
int say_hello_fn(char *name) {
printf("Hello %s\n", name);
return 0;
}
int say_goodbye_fn(void) {
printf("Goodbye\n");
return 0;
}
struct greet_api greet_api =
{
.say_hello = say_hello_fn,
.say_goodbye = say_goodbye_fn
};
int main(int argc, char const *argv[])
{
greet_api.say_hello(argv[1]);
greet_api.say_goodbye();
printf("%p, %p, %p\n", greet_api.say_hello, say_hello_fn, &say_hello_fn);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment