首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么判定一个声明为inline的函数在编译后是否真的扩展了

2013-03-16 
如何判定一个声明为inline的函数在编译后是否真的扩展了?如题,源代码如下:class test{public:void seta(in

如何判定一个声明为inline的函数在编译后是否真的扩展了?
如题,源代码如下:

class test
{
public:
    void seta(int a)
    {
        m_a = a;
    }
private:
    int m_a;
};
int main()
{
    test xxx;
    xxx.seta(32);
}

编译:g++ test.cpp
反汇编后如下:
(gdb) b main
Breakpoint 1 at 0x40055c
(gdb) r
Starting program: /home/zsong/a.out 

Breakpoint 1, 0x000000000040055c in main ()
(gdb) disassemble 
Dump of assembler code for function main:
0x0000000000400558 <main+0>:    push   %rbp
0x0000000000400559 <main+1>:    mov    %rsp,%rbp
0x000000000040055c <main+4>:    sub    $0x10,%rsp
0x0000000000400560 <main+8>:    lea    0xfffffffffffffff0(%rbp),%rdi
0x0000000000400564 <main+12>:   mov    $0x20,%esi
0x0000000000400569 <main+17>:   callq  0x400576 <_ZN4test4setaEi>
0x000000000040056e <main+22>:   mov    $0x0,%eax
0x0000000000400573 <main+27>:   leaveq 
0x0000000000400574 <main+28>:   retq   
End of assembler dump.
(gdb) 

可以看到还是有函数的调用【callq  0x400576 <_ZN4test4setaEi>】,难道这么绝对的inline都没有扩展?
[解决办法]
你没加-O……

热点排行