外部内联 [英] extern inline

查看:147
本文介绍了外部内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,内联本身是一个建议,编译器,并在其裁量它可能会或可能不会内联函数,它也将产生可连接对象code。

I understand that "inline" by itself is a suggestion to the compiler, and at its descretion it may or may not inline the function, and it will also produce linkable object code.

我认为,静态内联不相同(可能会或可能不会内联),但不会产生内联的时候(因为没有其他的模块可以链接到它)链接目标code。

I think that "static inline" does the same (may or may not inline) but will not produce linkable object code when inlined (since no other module could link to it).

在哪里extern内联融入画面?

Where does "extern inline" fit into the picture?

假设我想通过内联函数来替换一个preprocessor宏并要求该函数被内联(例如,因为它使用了__FILE__和__LINE__应解决呼叫者但此称为功能宏)。也就是说,我希望看到一个情况下,编译器或链接错误的功能没有得到内联。难道外部内联做到这一点? (我认为,如果没有,就没有办法实现比宏坚持其他的这种行为。)

Assume I want to replace a preprocessor macro by an inline function and require that this function gets inlined (e.g., because it uses the __FILE__ and __LINE__ macros which should resolve for the caller but not this called function). That is, I want to see a compiler or linker error in case the function does not get inlined. Does "extern inline" do this? (I assume that, if it does not, there is no way to achieve this behavior other than sticking with a macro.)

是否有C的差别++和C?

Are there differences between C++ and C?

是否有不同的编译器供应商和版本之间的差异?

Are there differences between different compiler vendors and versions?

推荐答案

在K&放大器; R C或C89,内联不是语言的一部分。许多编译器实现它作为一个扩展,但没有关于它如何工作没有明确的语义。海湾合作委员会是最早实施内联外,并推出了在线静态内联外部内联结构;最pre-C99编译器一般按照其领先地位。

in K&R C or C89, inline was not part of the language. Many compilers implemented it as an extension, but there were no defined semantics regarding how it worked. GCC was among the first to implement inlining, and introduced the inline, static inline, and extern inline constructs; most pre-C99 compiler generally follow its lead.


  • 在线:该函数可以被内联(这只是一个提示,虽然)。出的行的版本总是发射和外部可见。因此,你只能有一个编译单元定义成一个内联,和所有其他人需要把它看作超出线的功能(或者你会得到在链接时重复的符号)。

  • 静态内联不会产生外部可见外的行版本,虽然它可能会产生一个文件静态的。一定义规则不适用的,因为从来就没有一个发出外部符号也没有一个电话。

  • extern内联不会产生外的行的版本,但可能调用一(你因此必须用其它编译单元定义,其中1个定义规则适用,虽然,外的行版本必须具有相同的code作为这里提供的内联,如果编译器调用,而不是

  • 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).
  • 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.
  • 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.

  • 在线:像GNU外部内联;没有外部可见的功能是发出,但有可能被称为所以必须存在

  • extern内联:像GNU内联:外部可见code发出,所以至多只有一个翻译单位可以使用该

  • 静态内联:像GNU静态内联。这是gnu89和C99之间的唯一便携式有一个

  • inline: like GNU "extern inline"; no externally visible function is emitted, but one might be called and so must exist
  • extern inline: like GNU "inline": externally visible code is emitted, so at most one translation unit can use this.
  • static inline: like GNU "static inline". This is the only portable one between gnu89 and c99

这是任何地方内联函数必须是内联无处不在,具有相同的定义。编译器/连接器将整理符号的多个实例。没有静态内嵌的定义 extern内联,虽然许多编译器有他们(通常遵循gnu89模型)。

A function that is inline anywhere must be inline everywhere, with the same definition. The compiler/linker will sort out multiple instances of the symbol. There is no definition of static inline or extern inline, though many compilers have them (typically following the gnu89 model).

这篇关于外部内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆