讓我們想象一下,包含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的定義** –