always_inline

The always_inline function attribute instructs the compiler to inline a function. This function can be inlined when all of the following conditions are satisfied:
  • The function is an inline function that satisfies any of the following conditions:
    • The function is specified with the inline or __inline__ keyword.
    • The option -qinline+<function_name> is specified, where function_name is the name of the function to be inlined.
    • C++ only beginsThe function is defined within a class declaration.C++ only ends
  • The function is not specified with the noinline or __noinline__ attribute.
  • The number of functions to be inlined does not exceed the limit of inline functions that can be supported by the compiler.
Read syntax diagramSkip visual syntax diagram
always_inline function attribute syntax

>>-__attribute__--((--+-always_inline-----+--))----------------><
                      '-__always_inline__-'       

The noinline attribute takes precedence over the always_inline attribute. The always_inline attribute takes precedence over inlining compiler options only if inlining is enabled. The always_inline attribute is ignored if inlining is disabled.

C++ only beginsThe compiler might not inline a virtual function even when the function is specified with the always_inline attribute. The compiler will not issue an informational message to indicate that a virtual function is not inlined.

When you specialize a function template that is specified with the always_inline attribute, this attribute is propagated to the template specification. If you apply the always_inline attribute to the template specification, the duplicate always_inline attribute is ignored. See the following example.
template<class T> inline __attribute__((always_inline)) T test( ){
    return (T)0;
}

// The duplicate attribute "always_inline" is ignored.
template<> inline __attribute__((always_inline)) float test<float>(){
    return (float)0;
}   
C++ only ends


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us