fork download
  1. #include <iostream>
  2. #include <cstdint>
  3. void f()
  4. {
  5. std::cout << "foo\n";
  6. }
  7. int main()
  8. {
  9. void(*fptr)(void) = f;
  10. void(**fptrptr)() = &fptr;
  11. std::uintptr_t addr = reinterpret_cast<std::uintptr_t>(fptrptr);
  12. addr -= 4;
  13.  
  14. (
  15. (void(*)(void)) // cast to function pointer the following value
  16. (
  17. *( // obtain the value pointed to by the following
  18. (std::uintptr_t*)( // cast to intptr_t pointer
  19. addr+4 // add 4 to the integer
  20. )
  21. )
  22. )
  23. )(); // invoke the function pointer
  24. }
  25.  
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
foo