Skip to content

Instantly share code, notes, and snippets.

@xiam
Last active December 22, 2015 17:09
Show Gist options
  • Select an option

  • Save xiam/6504646 to your computer and use it in GitHub Desktop.

Select an option

Save xiam/6504646 to your computer and use it in GitHub Desktop.
Buscando algo con @toorandom y @nitr0usmx.
#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;
};
@xiam
Copy link
Author

xiam commented Sep 10, 2013

$ gcc -o main main.c && ./main
foo->b = 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment