C++函数很短, 但是函数内调用一个很长的函数, 该用inline吗?
高洛峰
高洛峰 2017-04-17 14:27:40
0
5
599
void x(){
    thisIsALongFunction();
}

如上图所示的代码, x()中只有一句话, 但是它所调用的函数很长, 这种情况下需要inline吗?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(5)
巴扎黑

In this case, the compiler will directly inline the outer function.

小葫芦

inlineThis is just a suggestion to the compiler, not a requirement.

However, the implementation of mainstream compilers will ignore your suggestions. If you turn on O2, short functions will be automatically inlined, but long functions will not be inlined. So ignore it.

阿神

Add it, inlining will remove your extra layer of encapsulation, and the encapsulation inside should still be there

黄舟

Don’t worry about these issues, it doesn’t matter whether the code optimized by the compiler is inline or not.

PHPzhong

First figure out what inline is for,

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template