What Does It Mean For a C++ Function To Be Inline?

后端 未结 9 796
攒了一身酷
攒了一身酷 2020-12-01 06:12

See title: what does it mean for a C++ function to be inline?

9条回答
  •  我在风中等你
    2020-12-01 07:19

    Informally, it means that compilers are allowed to graft the contents of the function onto the call site, so that there is no function call. If your function has big control statements (e.g., if, switch, etc.), and the conditions can be evaluated at compile time at the call site (e.g., constant values used at call site), then your code ends up much smaller (the unused branches are dropped off).

    More formally, inline functions have different linkage too. I'll let C++ experts talk about that aspect.

提交回复
热议问题