language: C++11 (gcc-4.7.2)
date: 193 days 5 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstdint>
void f()
{
    std::cout << "foo\n";
}
int main()
{
   void(*fptr)(void) = f;
   void(**fptrptr)() = &fptr;
   std::uintptr_t addr = reinterpret_cast<std::uintptr_t>(fptrptr);
   addr -= 4;
 
   (
      (void(*)(void)) // cast to function pointer the following value
      (
        *( // obtain the value pointed to by the following
          (std::uintptr_t*)( // cast to intptr_t pointer
            addr+4 // add 4 to the integer
           )
         )
      )
   )(); // invoke the function pointer
}