代码之家  ›  专栏  ›  技术社区  ›  Jack Nock

找出哪些函数是内联的

  •  11
  • Jack Nock  · 技术社区  · 15 年前

    当用GCC 4.4或MSVC编译C++时,当函数被内联时,编译器可以发出消息吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Cubbi    15 年前

    有了G++,我不认为你可以让G++报告这些,但是你可以用任何显示符号的工具检查生成的二进制文件, nm 例如:

    #include <iostream>
    struct T {
            void print() const;
    };
    void T::print() const { std::cout << " test\n" ; }
    int main()
    {
            T t;
            t.print();
    }
    
    ~ $ g++ -O3  -Wall -Wextra -pedantic -o test test.cc
    ~ $ nm test | grep print
    0000000000400800 t _GLOBAL__I__ZNK1T5printEv
    0000000000400830 T _ZNK1T5printEv
    

    VS

    #include <iostream>
    struct T {
            void print() const { std::cout << " test\n" ; }
    };
    int main()
    {
            T t;
            t.print();
    }
    ~ $ g++ -O3  -Wall -Wextra -pedantic -o test test.cc
    ~ $ nm test | grep print
    

    (第二种情况下无NM输出)

    编辑: 此外,可能会使用轮廓仪。gprof显示了这两个例子:

    0.00      0.00     0.00        1     0.00     0.00  global constructors keyed to _ZNK1T5printEv
    0.00      0.00     0.00        1     0.00     0.00  T::print() const
    

    VS只是

    0.00      0.00     0.00        1     0.00     0.00  global constructors keyed to main