fork download
  1. #include <stdio.h>
  2.  
  3. struct Structure {
  4. int a;
  5. void (*function)(struct Structure *);
  6. };
  7.  
  8. void foo(struct Structure *a) {
  9. if (a->function == NULL) a->function = foo;
  10. a->a++;
  11. printf("%d\n", a->a);
  12. }
  13.  
  14. int main(void) {
  15. struct Structure a = {42, foo};
  16. struct Structure b = {0}; // don't call b.function just yet!!
  17. a.function(&b); // foo(&b)
  18. b.function(&a); // foo(&a)
  19. }
  20.  
Success #stdin #stdout 0s 5520KB
stdin
Standard input is empty
stdout
1
43