fork(3) download
  1. #include <stdio.h>
  2.  
  3. typedef void* (*function_pointer_t)(int index);
  4.  
  5. struct function_holder {
  6. function_pointer_t callback;
  7. };
  8.  
  9. void* testFn(int i)
  10. {
  11. printf("testFn %d\n", i);
  12. }
  13.  
  14. int main(void) {
  15. struct function_holder fh = { testFn };
  16. struct function_holder* fhp = &fh;
  17.  
  18. fh.callback = testFn;
  19. fh.callback(1);
  20. fhp->callback(2);
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
testFn 1
testFn 2