内联关键字和链接 [英] inline keyword and linkage

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

问题描述

大家好,


据我所知,''inline''关键字是编译器提示

来考虑函数作为内联的候选人的问题,是吗?


当内联链接的函数被内联时会发生什么?应该

编译器是否仍然导出函数?


或者内联函数是否隐式静态?


是extern inline foo(){}一个合法的函数定义?


内联foo(...){}与内联foo(){}有什么不同?


阅读后,我有点困惑
http:// cpptips。 hyperformix.com/cpptips/extern_inline3

$ cat foo.cxx

extern inline int foo(int n)

{

int sum = 0;

for(int i = 0; i< n; ++ i)sum + = i;

返还金额;

}


$ g ++ - 3.4.3 -std = c ++ 98 -Wall -Wextra -pedantic -c foo。 cxx


$ nm foo.o

/ *没有符号出口* /


-

问候,Grumble

Hello everyone,

As far as I understand, the ''inline'' keyword is a hint for the compiler
to consider the function in question as a candidate for inlining, yes?

What happens when a function with extern linkage is inlined? Should the
compiler still export the function?

Or is an inlined function implicitly static?

Is extern inline foo() { } a legal function defintion?

Is inline foo(...) { } different from inline foo() { } ?

I was somewhat confused after reading
http://cpptips.hyperformix.com/cpptips/extern_inline3

$ cat foo.cxx
extern inline int foo(int n)
{
int sum = 0;
for (int i = 0; i < n; ++i) sum += i;
return sum;
}

$ g++-3.4.3 -std=c++98 -Wall -Wextra -pedantic -c foo.cxx

$ nm foo.o
/* NO SYMBOLS EXPORTED */

--
Regards, Grumble

推荐答案

cat foo.cxx

extern inline int foo(int n)

{

int sum = 0;

for(int i = 0;我< N; ++ i)sum + = i;

返回总和;

}

cat foo.cxx
extern inline int foo(int n)
{
int sum = 0;
for (int i = 0; i < n; ++i) sum += i;
return sum;
}


g ++ - 3.4.3 -std = c ++ 98 -Wall -Wextra -pedantic -c foo.cxx

g++-3.4.3 -std=c++98 -Wall -Wextra -pedantic -c foo.cxx


nm foo.o

/ *没有符号出口* /


-

问候,抱怨
nm foo.o
/* NO SYMBOLS EXPORTED */

--
Regards, Grumble


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

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