C + + inline functions

Source: Internet
Author: User

The inline function from the source layer, there is the structure of the function, but after compiling, but does not have the nature of the function.
The inline function does not take control over the call, but instead embeds the body of the function at compile time at each call.
At compile time, similar to macro substitution, use the function body to replace the function name at the call.
It is generally decorated with inline in the code, but the ability to form inline functions depends on the compiler's specific handling of the function definition.


The following points should be noted:
1, inline functions can reduce the CPU overhead, and the overall speed of the program will be accelerated, but when the inline function is large, it will have the opposite effect,

Therefore, an inline function is used in a generally smaller function.


2, there are two methods of declaration of inline functions, one is to use the inline closing word before the function, and the other is to define the code of the function inside the class.

Such functions are automatically converted to inline functions, and there is no need to put inline in front of the function.


3, inline is a request to the compiler, the following conditions will prevent the compiler to obey this request: The function contains a loop, switch or

A goto statement, a recursive function, a function that contains static.

Definitions of inline functions:
Inline should be used for function declarations (Declaration) rather than function implementations (implementation). But because of the different compilers under the inline

The calling scope of the function that the keyword modifies is inconsistent, so one simple approach is to combine the Declaration and implementation of the inline function. If the confirmation letter

Number applies only to the same file, we can place the declaration and implementation of the function in the. C/.cpp, otherwise put it in. h (this includes the header

Files can be used by any file).

C + + inline functions

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.