Why do inline functions have external linkage by default?

前端 未结 2 668
执笔经年
执笔经年 2020-12-30 02:30

The standard says that given a declaration of

inline void foo();

that foo is an inline function with external linkage (becaus

相关标签:
2条回答
  • 2020-12-30 02:58

    This is aptly answered here by Jonathan Schilling's article: Extern Inlines By Default.

    To quote him about motivation for this change:

    The immediate motivation for this change was a need of the new template compilation model that was adopted at the same meeting; but more generally it was felt that changing the default was an idea whose time had come, and the change was approved unanimously in both ANSI and ISO.

    0 讨论(0)
  • 2020-12-30 03:17

    One result of that decision is that a static variable defined within an inline function will be shared between all instantiations of the function. If the default had been internal linkage, each translation unit would have gotten its own copy of the static variable. That's not how people expect things to work - inline vs. non-inline shouldn't affect the code semantics so drastically.

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