41

I have found the following function definition :

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

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

0

2 Answers 2

81

The often referenced gcc documentation for always_inline is incomplete.

always_inline attribute makes gcc compiler:

  • Ignore -fno-inline (this is what the documentation says).
  • Ignore the inlining limits hence inlining the function regardless. It also inlines functions with alloca calls, which inline keyword never does.
  • Not produce an external definition of a function with external linkage if marked with always_inline.

The source of the above information is gcc source code, and, hence, is subject to change with no warning.

An interesting bechmark: always_inline performance.

1
  • icc also apply it now Commented Jul 20, 2021 at 3:30
25

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.