fork download
  1. #include <stdio.h>
  2.  
  3. typedef void* (*Fn) ();
  4.  
  5. int Fun()
  6. {
  7. return 5;
  8. }
  9.  
  10. float fFun()
  11. {
  12. return 5.0;
  13. }
  14.  
  15.  
  16. void callfun(Fn f)
  17. {
  18. printf ("%d \n", f());
  19. }
  20.  
  21. void callffun(Fn f)
  22. {
  23. printf ("%f \n", f());
  24. }
  25.  
  26.  
  27.  
  28. int main()
  29. {
  30.  
  31. callfun(Fun); // works
  32. callffun(fFun); // --> doesnt work ??
  33. printf ("%f", fFun()); // works
  34.  
  35. return 0;
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘callfun’:
prog.c:18:5: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘void *’ [-Werror=format]
prog.c: In function ‘callffun’:
prog.c:23:5: error: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘void *’ [-Werror=format]
prog.c: In function ‘main’:
prog.c:31:1: error: passing argument 1 of ‘callfun’ from incompatible pointer type [-Werror]
prog.c:16:6: note: expected ‘Fn’ but argument is of type ‘int (*)()’
prog.c:32:1: error: passing argument 1 of ‘callffun’ from incompatible pointer type [-Werror]
prog.c:21:6: note: expected ‘Fn’ but argument is of type ‘float (*)()’
cc1: all warnings being treated as errors
stdout
Standard output is empty