我發現下面的函數定義:什麼「inline __attribute __((always_inline))」是指在函數中?
static inline __attribute__((always_inline)) int fn(const char *s)
{
return (!s || (*s == '\0'));
}
而且我想知道的inline __attribute__((always_inline))
意思?
我發現下面的函數定義:什麼「inline __attribute __((always_inline))」是指在函數中?
static inline __attribute__((always_inline)) int fn(const char *s)
{
return (!s || (*s == '\0'));
}
而且我想知道的inline __attribute__((always_inline))
意思?
即使禁用了優化,它也會強制編譯器內聯函數。請檢查this documentation獲取更多信息。
always_inline
經常提到的gcc文檔是不準確的。
此屬性使編譯器忽略-fno-inline
(這是文檔說的)和內聯限制因此內聯函數。此外,它還調用alloca
調用功能,而inline
關鍵字從來不會這樣做。
一個有趣的bechmark:always_inline
performance。
你看過[文檔](http://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Function-Attributes.html)? –
@OliCharlesworth很清楚他沒有。我在google上搜索了20秒鐘的「GCC inline keyword」搜索後才寫出了答案(搜索只是爲了提供一個參考答案)。 linuxcdeveloper:**在發佈SO之前,嘗試做一些個人的努力。我們不在這裏做你的工作,我們在這裏幫助。** – Manu343726