Original link: http://blog.csdn.net/yuan1125/article/details/6225993
1 inline is just a compiler recommendation, and the compiler does not necessarily have to expand the inline function.
For example:
inline function Address Reference
Inline is used in recursive functions
2 inline must be used for function definitions, and inline does not work for function declarations
For example:
Inline Max (int,int); No inline effect
Only inline max (int a,int b)
{
......
}
Only use it.
3 inline defines functions and macro definitions just as local files are visible. Therefore, it is recommended that the function defined by the inline be placed in the header file
4 The rules of the inline function in GCC
1. Static inline---> compiler is expanded locally.
2. Inline---> Local expansion, field-generated independent assembly code for the inline function
3. extern inline---> does not generate separate assembly code.
Feature 1. The call to this function is processed into an external reference, even if it is applied by a pointer or is recursive, and does not cause the compiler to generate a sink encoding for it.
Feature 2.extern inline functions allow the same name as an external function, meaning that it is also legal to define an extern inline function with the same names in the presence of an externally defined global library function.
The use of extern inline:
Within the C file of a library function, define a generic version of the library function foo:
MYLIB.C:
void Foo ()
{
...;
}
And then in its header file, define (note not declaration!) ) A version that implements the same Exterin inline:
Mylib.h:
extern inline Foo ()
{
...;
}
So when other files are going to use this library function, the compiler will use the extern inline version of the header file as long as the include Mylib.h, where it can be expanded inline.
In the case where it cannot be expanded (such as a function pointer reference), the compiler will refer to the MYLIB.C version of the standalone compilation.
That looks like a function that can be inline externally, so this should be the origin of the extern inline meaning of gcc.
C-language inline function (GO)