让我们想象一下,包含blah.h头文件:编译器是否会在没有主体的情况下内联函数?
// A declaration without any code. We force inline
__attribute__((always_inline)) void inline_func();
而且包含blah.cpp源文件:
#include "blah.h"
// The code of the inline function
void inline_func() {
...
}
// Use the inline function
void foo() {
inline_func();
}
的问题是,将编译器实际上内联inline_func()
?代码应该与声明一起使用,还是可以分开使用?
- 假设没有LTO
- 注意在
inline_func()
他们将与LTO内联,这可能会变得非常平常(也许稍后会隐式启用)。 **这种内联是LTO的定义** –