inline
is a keyword of C++, but inlining is a generic process performed by a compiler backend, usually after instruction sequences are already generated.
A C compiler will also inline functions, and a C++ compiler will inline functions that aren't inline
. A C++ compiler can also fail to inline an inline
function for any arbitrary reason. The keyword actually exists to specify that a function may have multiple, identical definitions in different translation units (source files).
Static variables have no special bearing on whether something can be inlined. Perhaps some compilers have difficulty linking the resulting structure of global variable references, but that's more of a bug than a rule of thumb.
Recursive functions can be inlined, too. The recursive call should be translated to a branch. The branch could then be targeted by loop unrolling.
A function that compiles to more than a kilobyte of code will usually not be inlined. But a compiler may provide #pragma
directives or platform-specific attributes to force inlining in such a case.
The biggest factor that would stop a function from being inlined is if its source isn't available to the compiler at the time of code generation. Link-time optimization opens the possibility of inlining functions that are extern
and not inline
but a function supplied by a DLL is certainly off limits. But then, you could still run it through a JIT style execution engine and that could inline (splice together) any random fragments it likes.