我用内联函数读取了函数调用,我们用函数定义的主体替换函数调用。
根据上述说明,当inline
是用户时,不应该有任何函数调用。
如果是这种情况为什么我在汇编代码中看到三条call
指令?
#include <iostream>
inline int add(int x, int y)
{
return x+ y;
}
int main()
{
add(8,9);
add(20,10);
add(100,233);
}
meow@vikkyhacks ~/Arena/c/temp $ g++ -c a.cpp
meow@vikkyhacks ~/Arena/c/temp $ objdump -M intel -d a.o
0000000000000000 <main>:
0: 55 push rbp
1: 48 89 e5 mov rbp,rsp
4: be 09 00 00 00 mov esi,0x9
9: bf 08 00 00 00 mov edi,0x8
e: e8 00 00 00 00 call 13 <main+0x13>
13: be 0a 00 00 00 mov esi,0xa
18: bf 14 00 00 00 mov edi,0x14
1d: e8 00 00 00 00 call 22 <main+0x22>
22: be e9 00 00 00 mov esi,0xe9
27: bf 64 00 00 00 mov edi,0x64
2c: e8 00 00 00 00 call 31 <main+0x31>
31: b8 00 00 00 00 mov eax,0x0
36: 5d pop rbp
37: c3 ret
目标文件的完整转储为here
答案 0 :(得分:6)
见第28页: http://www.cs.princeton.edu/courses/archive/spr04/cos217/lectures/Assembler.pdf