GCC 内联 C++ 函数是否没有“inline"关键字?

Does GCC inline C++ functions without the #39;inline#39; keyword?(GCC 内联 C++ 函数是否没有“inline关键字?)
本文介绍了GCC 内联 C++ 函数是否没有“inline"关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在编译 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"关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

OpenGL transforming objects with multiple rotations of Different axis(OpenGL 变换不同轴多次旋转的对象)
GLFW first responder error(GLFW 第一响应者错误)
SOIL not linking correctly(SOIL 连接不正确)
Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1(核心配置文件与版本字符串?在 mesa 10.0.1 中只获得 GLSL 1.3/OGL 3.0)
What is the range of OpenGL texture ID?(OpenGL 纹理 ID 的范围是多少?)
How taxing are OpenGL glDrawElements() calls compared to basic logic code?(与基本逻辑代码相比,OpenGL glDrawElements() 调用的繁重程度如何?)