C语言 “inline __attribute__((always_inline))”在函数中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22767523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:57:22  来源:igfitidea点击:

what “inline __attribute__((always_inline))” means in the function?

cgcc

提问by developer

I have found the following function definition :

我找到了以下函数定义:

static inline __attribute__((always_inline)) int fn(const char *s)
{
  return (!s || (*s == '##代码##'));
}

And I want to know the meaning of inline __attribute__((always_inline))?

我想知道inline __attribute__((always_inline))?

回答by Maxim Egorushkin

The often referred gcc documentation for always_inlineis inaccurate.

经常提到的 gcc 文档always_inline是不准确的。

This attribute makes the compiler ignore -fno-inline(this is what the documentation says) and the inlining limitshence inlining the function anyway. Also, it inlines functions with allocacalls, which inlinekeyword never does.

这个属性使编译器忽略-fno-inline(这是文档所说的)和内联限制,因此无论如何内联函数。此外,它使用alloca调用内联函数,而inline关键字从不这样做。

An interesting bechmark: always_inlineperformance.

一个有趣的基准:always_inline性能

回答by Manu343726

It forces the compiler to inline the function even if optimizations are disabled. Check this documentationfor more information.

即使优化被禁用,它也会强制编译器内联函数。查看此文档以获取更多信息。