Skip to content

Instantly share code, notes, and snippets.

@mehmetaydogduu
Created September 2, 2018 21:25
Show Gist options
  • Save mehmetaydogduu/bb557f7235232863c302ce3b2b2c11c7 to your computer and use it in GitHub Desktop.
Save mehmetaydogduu/bb557f7235232863c302ce3b2b2c11c7 to your computer and use it in GitHub Desktop.
C - function inside struct - Javascript Like Solution
# Copy from https://stackoverflow.com/a/32964582/7595238
#include <stdio.h>
typedef struct hello {
int (*someFunction)();
} hello;
int foo() {
return 0;
}
hello Hello() {
struct hello aHello;
aHello.someFunction = &foo;
return aHello;
}
int main()
{
struct hello aHello = Hello();
printf("Print hello: %d\n", aHello.someFunction());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment