在 K&R C 或 C89 中,内联不是语言的一部分.许多编译器将其实现为扩展,但没有关于它如何工作的定义语义.GCC 是最先实现内联的,并引入了 inline、static inline 和 extern inline 结构;大多数 C99 之前的编译器通常都跟随它的步伐.
- inline:函数可以被内联(不过这只是一个提示).外部版本总是发出并且外部可见.因此,您只能在一个编译单元中定义这样的内联,而其他每个编译单元都需要将其视为外联函数(否则您将在链接时得到重复的符号).
- extern inline 不会生成外联版本,但可能会调用一个(因此您必须在其他某个编译单元中定义它.不过,一个定义规则适用;out-of-line 版本必须具有与此处提供的内联相同的代码,以防编译器调用它.
- static inline 不会生成外部可见的外联版本,尽管它可能会生成文件静态版本.单一定义规则不适用,因为从来没有发出过外部符号,也没有调用过.
- inline: the function may be inlined (it's just a hint though). An out-of-line version is always emitted and externally visible. Hence you can only have such an inline defined in one compilation unit, and every other one needs to see it as an out-of-line function (or you'll get duplicate symbols at link time).
- extern inline will not generate an out-of-line version, but might call one (which you therefore must define in some other compilation unit. The one-definition rule applies, though; the out-of-line version must have the same code as the inline offered here, in case the compiler calls that instead.
- static inline will not generate a externally visible out-of-line version, though it might generate a file static one. The one-definition rule does not apply, since there is never an emitted external symbol nor a call to one.
- inline:像GNU89extern inline";不发出任何外部可见的函数,但可能会被调用,因此必须存在
- extern inline:像GNU89内联":发出外部可见的代码,所以最多一个翻译单元可以使用它.
- static inline:类似于 GNU89 的静态内联".这是 gnu89 和 c99 之间唯一可移植的
- inline: like GNU89 "extern inline"; no externally visible function is emitted, but one might be called and so must exist
- extern inline: like GNU89 "inline": externally visible code is emitted, so at most one translation unit can use this.
- static inline: like GNU89 "static inline". This is the only portable one between gnu89 and c99
在任何地方内联的函数必须在任何地方内联,具有相同的定义.编译器/链接器将整理出符号的多个实例.static inline 或 extern inline 没有定义,尽管许多编译器都有它们(通常遵循 gnu89 模型).
这篇关于extern inline 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持前端之家!
本文链接:https://www.f2er.com/3188529.html