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

前端 未结 2 1364
心在旅途
心在旅途 2020-12-05 19:26

I have found the following function definition :

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


        
相关标签:
2条回答
  • 2020-12-05 19:50

    The often referred gcc documentation for always_inline is inaccurate.

    This attribute makes the compiler ignore -fno-inline (this is what the documentation says) and the inlining limits hence inlining the function anyway. Also, it inlines functions with alloca calls, which inline keyword never does.

    An interesting bechmark: always_inline performance.

    0 讨论(0)
  • 2020-12-05 20:07

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

    0 讨论(0)
提交回复
热议问题