本文作为帖子《如何知道一个函数在编译后是否被inline了? [》的总结,写入我的学习笔记博客,供需要的人包括自己查阅(好记性不如烂笔头子)。
要知道函数是否被inline,首先要打开编译器的inline功能,其次,要生成汇编代码,查看调用该函数的地方是否被inline。当然,如果在汇编中被inline那么在编译后的程序中一定是inline的;如果汇编中没有被inline,也不能说明函数不会在link时被inline;即使在link时没有被inline,也不能说明在运行时不会被inline。
1、VC
inline扩展选项:/Ob<n> inline expansion (default n=0)
0
输出汇编选项:/Fa[file] name assembly listing file /FA[scu] configure assembly listing
The arguments control the generation of source code and machine code and the extension of the listing file.
The following table describes the various values to /FA. It is possible to specify more than one value to /FA. For example, you can specify /FAsu.
Option |
Listing contents and file extension |
---|---|
/FA |
Assembly code; .asm |
/FAc |
Machine and assembly code; .cod |
/FAs |
Source and assembly code; .asm If /FAcs is specified, the file extension will be .cod |
/FAu |
Causes the output file to be created in UTF-8 format, with a byte order marker. By default, the file encoding is ANSI, but use /FAu if you want a listing file that displays correctly on any system, or if you are using Unicode source code files as input to the compiler. If /FAsu is specified, and if a source code file uses Unicode encoding other than UTF-8, then the code lines in the .asm file may not display correctly. |
By default, the listing file gets the same base name as the source file. You can change the name of the listing file and the directory where it is created using the /Fa option.
/Fa usage |
Result |
---|---|
/Fa |
One source_file.asm is created for each source code file in the compilation. |
/Fafilename |
filename.asm is placed in the current directory. Only valid when compiling a single source code file. |
/Fafilename.extension |
filename.extension is placed in the current directory. Only valid when compiling a single source code file. |
/Fadirectory\ |
One source_file.asm is created and placed in the specified directory for each source code file in the compilation. Note the required trailing backslash. Only paths on the current disk are allowed. |
/Fadirectory\filename |
filename.asm is placed in the specified directory. Only valid when compiling a single source code file. |
/Fadirectory\filename.extension |
filename.extension is placed in the specified directory. Only valid when compiling a single source code file. |
2、g++