“在线”的有用性特点 [英] Usefulness of the "inline" feature

查看:96
本文介绍了“在线”的有用性特点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内联有两个方面:




  • inline 关键字将被忽略如果编译器确定函数不能内联。

  • 有一个编译器优化(在Visual Studio上,我不知道GCC),告诉编译器内联所有函数。



从这里我得出结论,我从来不需要麻烦内联。



或者是否有任何情况下会优先使用手动内联?


< inline 关键字有两个函数:




  • 它可以作为编译器执行内联优化的提示(这在现代编译器上基本上是无用的,它在有或没有关键字的情况下内联)

  • 它告诉编译器/链接器忽略一个定义规则: inline 'd符号可以在多个翻译单元中定义(通常是因为它定义在头部,包括多个文件)。通常,这将导致链接器错误,但是当您使用 inline 关键字时允许。


There's two things about inlining:

  • The inline keyword will be ignored if the compiler determines that the function cannot be inlined.
  • There is a compiler optimization (on Visual Studio, I don't know about GCC) that tells the compiler to inline all functions where possible.

From this I conclude that I never need to bother about inlining. I just have to turn on the compiler optimization for the release build.

Or are there any situations where manually inlining would be preferred?

解决方案

The inline keyword has two functions:

  • it serves as a hint to the compiler to perform the inlining optimization (this is basically useless on modern compilers, which inline aggressively with or without the keyword)
  • it tells the compiler/linker to ignore the One Definition Rule: that the inline'd symbol may be defined in multiple translation units (typically because it is defined in a header, that is included from multiple files). Normally, this would result in a linker error, but it is allowed when you use the inline keyword.

这篇关于“在线”的有用性特点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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