Last active
December 22, 2015 17:09
-
-
Save xiam/6504646 to your computer and use it in GitHub Desktop.
Buscando algo con @toorandom y @nitr0usmx.
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 <stdlib.h> | |
| #include <stdio.h> | |
| typedef struct temp { | |
| int a; | |
| int (*b)(struct temp*, int); // queremos quitar el struct temp* de aquí. | |
| } temp_t; | |
| // ...Y envolver B. | |
| int B(temp_t *self, int x) { | |
| return self->a + x; | |
| } | |
| int main() { | |
| temp_t *foo; | |
| foo = (struct temp*)malloc(sizeof(struct temp)); | |
| foo->a = 41; | |
| foo->b = B; | |
| // Jala así | |
| printf("foo->b = %d\n", foo->b(foo, 1)); | |
| // Pero buscamos | |
| // printf("foo->b = %d\n", foo->b(1)); | |
| return -1; | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ gcc -o main main.c && ./main
foo->b = 42