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

前端 未结 8 1258
余生分开走
余生分开走 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:40

    Inlining is not a linker function.

    The toolchains that support whole program optimization (cross-TU inlining) do so by not actually compiling anything, just parsing and storing an intermediate representation of the code, at compile time. And then the linker invokes the compiler, which does the actual inlining.

    This is not done by default, you have to request it explicitly with appropriate command-line options to the compiler and linker.

    One reason it is not and should not be default, is that it increases dependency-based rebuild times dramatically (sometimes by several orders of magnitude, depending on code organization).

    0 讨论(0)
  • 2021-02-07 07:42

    Yes, any decent compiler is fully capable of inlining that function if you have the proper optimisation flags set and the compiler deems it a performance bonus.

    If you really want to know, add a breakpoint before your function is called, compile your program, and look at the assembly. It will be very clear if you do that.

    0 讨论(0)
提交回复
热议问题