Reprint Address: http://blog.chinaunix.net/uid-26285146-id-3225668.html
Today, looking at the HAL layer header file, see static inline int sensors_open, inline some do not understand, in this record
Inline functions are somewhat similar to macro. The code for the inline function is embedded directly in the place where it was invoked, and the call is embedded several times, without using the calling command. This eliminates some of the extra overhead of function calls, such as saving and restoring function return addresses, to speed up. However, the number of calls can make the executable file larger, which slows down. Kernel developers generally prefer to use inline functions compared to macros. Because inline functions have no length limitations, formatting restrictions. The compiler can also check how the function is invoked to prevent its misuse.
The inline function of the static inline, usually does not produce the code of the function itself, but is all embedded in the called Place. If you do not add static, the function may be invoked by other compilation units, so the code for the function itself must be generated. So the static is added, which generally makes the executable file smaller. The kernel generally does not see the use of inline only, but the use of static inline.
Inline
The keyword inline indicates the executable code to optimize the function, which can be implemented by merging the code of the function into the code of the calling program. Most of the inline functions used by the Linux kernel are defined as static types. A "static inline" function prompts the compiler to attempt to insert its code into all programs that invoke it.
This merge can exempt any overhead from function calls, #define语句也可以排除额外的函数调用.
In addition, using inline increases the size of the binary image, which reduces the speed at which the CPU cache is accessed, so it cannot be used in all function definitions.