How do I know if a function has been inlined or not?
If I mark any function as inline, is there a way I can know if the function gets inlined 开发者_Go百科or not?
With GCC you can use -Winline
compiler option:
-Winline Warn if a function can not be inlined and it was declared as inline.
The man
file for gcc goes on to say:
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.
Look at the assembly language that your compiler emits. For example, compiling with g++:
g++ -S -c foo.c
will create a file called foo.s containing the assembly language output. Alternatively, and once again with the GCC toolset, use objdump:
g++ -c foo.c
objdump -d foo.o
Other toolsets have similar functionality.
1, Look at the assembler output
2, why do you care?
精彩评论