1. 程式人生 > >如何識別程式碼是否被inline了?

如何識別程式碼是否被inline了?

本文作為帖子《如何知道一個函式在編譯後是否被inline了? [》的總結,寫入我的學習筆記部落格,供需要的人包括自己查閱(好記性不如爛筆頭子)。

要知道函式是否被inline,首先要開啟編譯器的inline功能,其次,要生成彙編程式碼,檢視呼叫該函式的地方是否被inline。當然,如果在彙編中被inline那麼在編譯後的程式中一定是inline的;如果彙編中沒有被inline,也不能說明函式不會在link時被inline;即使在link時沒有被inline,也不能說明在執行時不會被inline。

1、VC

inline擴充套件選項:/Ob<n> inline expansion (default n=0)

0

Disables inline expansion, which is on by default.

1

Expands only functions marked as inline, __inline, __forceinline or __inline or, in a C++ member function, defined within a class declaration.

2

Expands functions marked as inline or __inline

and any other function that the compiler chooses (expansion occurs at the compiler's discretion, often referred to as auto-inlining).

/Ob2 is in effect when /O1, /O2 (Minimize Size, Maximize Speed) or /Ox (Full Optimization) is used.

This option requires that you enable optimizations using /O1, /O2

, /Ox, or /Og.

輸出彙編選項:/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++