GCC内联C ++函数没有'inline'关键字? [英] Does GCC inline C++ functions without the 'inline' keyword?

查看:159
本文介绍了GCC内联C ++函数没有'inline'关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC在编译C ++代码时,是否尝试通过选择未标记 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?

推荐答案

是的。任何编译器都可以随意内联任何函数,当它认为这是一个好主意。

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.

这篇关于GCC内联C ++函数没有'inline'关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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