Does GCC inline C++ functions without the #39;inline#39; keyword?(GCC 内联 C++ 函数是否没有“inline关键字?)
问题描述
在编译 C++ 代码时,GCC 是否曾尝试通过选择内联未用 inline
关键字标记的函数来优化速度?
Does GCC, when compiling C++ code, ever try to optimize for speed by choosing to inline functions that are not marked with the inline
keyword?
推荐答案
是的.任何编译器只要认为它是一个好主意,都可以自由地内联任何函数.GCC 也这样做.
Yes. Any compiler is free to inline any function whenever it thinks it is a good idea. GCC does that as well.
在 -O2
优化级别,内联在编译器认为值得做(使用启发式)并且如果它不会增加代码.在 -O3
处,只要编译器认为值得做,就会执行,而不管它是否会增加代码的大小.此外,在所有优化级别(即启用的优化)中,内联只调用一次的静态函数.
At -O2
optimization level the inlining is done when the compiler thinks it is worth doing (a heuristic is used) and if it will not increase the size of the code. At -O3
it is done whenever the compiler thinks it is worth doing, regardless of whether it will increase the size of the code. Additionally, at all levels of optimization (enabled optimization that is), static functions that are called only once are inlined.
正如下面的评论中所指出的,这些 -Ox
实际上是包含多个更具体设置的复合设置,包括与内联相关的设置(如 -finline-functions
和这样),所以我们也可以根据那些更具体的设置来描述行为(并控制它).
As noted in the comments below, these -Ox
are actually compound settings that envelop multiple more specific settings, including inlining-related ones (like -finline-functions
and such), so one can also describe the behavior (and control it) in terms of those more specific settings.
这篇关于GCC 内联 C++ 函数是否没有“inline"关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GCC 内联 C++ 函数是否没有“inline"关键字?


- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01