Why do inline functions have external linkage by default?

前端 未结 2 677
执笔经年
执笔经年 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 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.

提交回复
热议问题