我如何知道函数是否已内联?

时间:2010-04-06 15:09:57

标签: c++ inline

如果我将任何函数标记为内联,有没有办法可以知道函数是否内联?

3 个答案:

答案 0 :(得分:27)

使用GCC,您可以使用-Winline编译器选项:

  -Winline  Warn if a function can not be inlined and it was declared as inline.

gcc的man文件继续说:

  Even with this option, the compiler will not warn about
  failures to inline functions declared in system headers.

  The compiler uses a variety of heuristics to determine whether or
  not to inline a function.  For example, the compiler takes into
  account the size of the function being inlined and the amount of
  inlining that has already been done in the current function.
  Therefore, seemingly insignificant changes in the source program
  can cause the warnings produced by -Winline to appear or disappear.

答案 1 :(得分:9)

查看编译器发出的汇编语言。例如,使用g ++进行编译:

g++ -S -c foo.c

将创建一个名为foo.s的文件,其中包含汇编语言输出。或者,再次使用GCC工具集,使用objdump:

g++ -c foo.c
objdump -d foo.o

其他工具集具有类似的功能。

答案 2 :(得分:6)

1,查看汇编程序输出
2,你为什么关心?