c – 什么是“extern inline”功能和什么时候使用?

前端之家收集整理的这篇文章主要介绍了c – 什么是“extern inline”功能和什么时候使用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有这样的东西,它在最新的C草案中:

在§7.1.2 .4:

An inline function shall be defined in every translation unit in which
it is odr-used and shall have exactly the same definition in every
case (3.2). [ Note: A call to the inline function may be encountered
before its definition appears in the translation unit. — end note ] If
the definition of a function appears in a translation unit before its
first declaration as inline,the program is ill-formed. If a function
with external linkage is declared inline in one translation unit,it
shall be declared inline in all translation units in which it appears;
no diagnostic is required. An inline function with external linkage
shall have the same address in all translation units. A static local
variable in an extern inline function always refers to the same
object. A type defined within the body of an extern inline function is
the same type in every translation unit.

一些洞察这是什么和什么时候使用它?

解决方法

extern对于函数是多余的,所以在内部声明一个函数是没有意义的.例如,如果您在全局范围内内联函数,则本节的规则将适用.同样,如果您在全局范围内声明了一个类,并在类定义中定义了一个成员函数,因此这个函数将是内联的.

你什么时候应该在内部声明函数是一个蠕虫病毒,我不会在这里打开.见:When should I write the keyword ‘inline’ for a function/method?

原文链接:https://www.f2er.com/c/115119.html

猜你在找的C&C++相关文章