“& inline& amp;"C ++中的关键字 [英] The "inline" keyword in C++

查看:57
本文介绍了“& inline& amp;"C ++中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,关键字内联"会导致该调用正确地被函数主体替换?所以我猜这意味着我们完全跳过了通话?就像我们查看.asm文件一样,找不到呼叫指令吗?

So the keyword "inline" will result in the call being replaced by the body of the function correct? So I'm guessing that means we skip the call entirely? Like if we look at the .asm file we wouldn't find a call instruction?

推荐答案

关键字 inline 具有误导性-进行实际的内联既没有必要,也没有足够的意义.它所做的一切:告诉链接器允许该函数的多个定义,这意味着您可以将该函数放在标头中.完成后,编译器将有更好的内联机会,因为在更多地方可以看到函数体.在现代系统中,如果它们使用整个代码优化就不再重要.

Keyword inline is misleading - it is neither necessary nor sufficient for actual inlining to happen. All it does: it tells the linker to allow multiple definitions of the function, which means you can place the function in a header. Once you do it, the compiler has a better chance to inline since the function body becomes visible in more places. In modern systems, it is not important anymore if they use whole code optimization.

一旦编译器有内联的机会,它就必须确定它是否对您要求它进行的任何优化(例如,针对速度进行优化)是否有益.

Once the compiler has a chance to inline, it has to decide whether it is beneficial for whatever optimization you asked it to do (e.g. optimize for speed).

如果编译器决定内联,那么您所说的.asm文件是正确的-无需调用该函数.

If the compiler decides to inline, then what you say about .asm file is correct - no call of the function.

这篇关于“& inline& amp;"C ++中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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