Will C++ linker automatically inline functions (without “inline” keyword, without implementation in header)?

前端 未结 8 1420
余生分开走
余生分开走 2021-02-07 06:42

Will the C++ linker automatically inline \"pass-through\" functions, which are NOT defined in the header, and NOT explicitly requested to be \"inlined\" through the

8条回答
  •  时光取名叫无心
    2021-02-07 07:20

    The inline keyword only acts as a guidance for the compiler to inline functions when doing optimization. In g++, the optimization levels -O2 and -O3 generate different levels of inlining. The g++ doc specifies the following : (i) If O2 is specified -finline-small-functions is turned ON.(ii) If O3 is specified -finline-functions is turned ON along with all options for O2. (iii) Then there is one more relevant options "no-default-inline" which will make member functions inline only if "inline" keyword is added.

    Typically, the size of the functions (number of instructions in the assembly), if recursive calls are used determine whether inlining happens. There are plenty more options defined in the link below for g++:

    http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

    Please take a look and see which ones you are using, because ultimately the options you use determine whether your function is inlined.

提交回复
热议问题