如何识别代码是否被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++

猜你喜欢

转载自blog.csdn.net/fibbery/article/details/8504127