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

前端 未结 8 1238
余生分开走
余生分开走 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).

提交回复
热议问题