内联函数和外部链接 [英] Inline functions and external linkage

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

问题描述

在此回答 http://stackoverflow.com/a/4193698/738811 中写道:内联函数默认有外部链接。但是,默认情况下不可能链接到内联的内容。那么,有什么意义说,内联函数有外部链接?

In this answer http://stackoverflow.com/a/4193698/738811 it's written that "Inline functions by default have external linkage". However it's not possible by default to link against something what is inline. So what's the sense to say that inline functions have external linkage?

推荐答案

名称的链接与什么地方无关,

The linkage of a name has nothing to do with where or how it is defined, just with where the name may be used to refer to a particular object or function.

声明一个内联函数不会强制它被内联;它只是放宽了单一定义规则,以允许在每个翻译单元中使用它(并且在每个翻译单元中需要一个定义),以使其更容易内联。它不会阻止生成非内联版本,如果编译器决定不内联对它的特定调用,或者如果你获取它的地址。

Declaring a function inline does not force it to be inlined; it just relaxes the One Definition Rule to allow a definition in each translation unit in which it's used (and require one in each translation unit in which it's called), to make it easier to inline. It doesn't prevent a non-inline version being generated, if the compiler decides not to inline a particular call to it, or if you take the address of it.

所以外部链接和内联不是排他的; 外部链接意味着该功能可以在任何翻译单元中被引用,并且内联意味着它必须在调用它的任何翻译单元中定义。

So "external linkage" and "inline" are not exclusive; "external linkage" means that the function may be referred to in any translation unit, and "inline" means that it must be defined in any translation unit that calls it.

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

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