使用 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
Run Code Online (Sandbox Code Playgroud)
与
#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
Run Code Online (Sandbox Code Playgroud)
(在第二种情况下 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
Run Code Online (Sandbox Code Playgroud)
与只是
0.00 0.00 0.00 1 0.00 0.00 global constructors keyed to main
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
445 次 |
| 最近记录: |