如何識別程式碼是否被inline了?
本文作為帖子《如何知道一個函式在編譯後是否被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++