C language inline generally not used alone, but with the static inline joint use

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.