Advertisement
quantumech

Untitled

Apr 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <emscripten.h>
  4.  
  5. // Define a type for a function pointer that retruns an integer and takes no arguements
  6. typedef int (*intFPtr)();
  7.  
  8. // This method gets called by JS as a way to pass in the address of the JS method
  9. EMSCRIPTEN_KEEPALIVE
  10. void callFuncPtr(int rawFuncAddr)
  11. {
  12.     // Cast address to function pointer
  13.     intFPtr func = (intFPtr)(rawFuncAddr);
  14.  
  15.     // Invoke the function pointer and print its result
  16.     printf("%d\n", func());
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement