Incrementing function pointers

后端 未结 5 1314
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 15:36

I just learned about function pointers (pointers pointing at the adress where where the machine code of a function is stored). This made me think about machine code and how

5条回答
  •  没有蜡笔的小新
    2021-01-17 16:17

    1. Machine code can be stored non-consecutively. Compiler feels free to split or merge some functions (in optimisation)
    2. If you manually increase a pointer to function you will probably get into middle of function, which is wrong.
    3. Debugging routines are already available: you can obtain stack traces of current execution point and resolve function names where execution pointers in stack do belongs (man backtrace, man backtrace_symbols). With addr2line you can convert them to line numbers.

提交回复
热议问题