-
-
Save droxer/30edcce84de162b24fbe to your computer and use it in GitHub Desktop.
OO implementation by C.
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> | |
| 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