inline function inline and macro definition deep parsing _c language

Source: Internet
Author: User

Advantages of inline functions:
One: the inline function of the class defined by inline, the code of the function is put into the symbol table and replaced directly (as the macro definition expands), without the overhead of the call, the efficiency is high.
Second: The introverted function of a class is a real function.
Three: Use inline function inline to completely replace the macro definition of an expression form.

Example:

Copy Code code as follows:

Class A
{
Public
int Readtest ()
{
return ntest;
}
void settest (int i);
};
inline void a::settest (int i)
{
ntest=i;
};

Note: the member functions of Class A readtest () and settest () are inline functions, the definition of the readtest () function is placed in the class declaration, and Readtest () is automatically converted to the inline function. The definition body of the settest function is outside the class declaration, so add the inline keyword.

Summarize the difference between a inline function and a macro definition:
1. The introverted function expands at compile time, and the macro is expanded when precompiled
2, at compile time the introverted function can be embedded directly into the target function code, while the macro is just a simple text replacement
3, the introverted function can complete such as the type of detection, statement is correct and other compile functions, macros do not have this function
4, the macro is not a function, and the inline function is a function
5, macro in the definition to be careful to handle macro parameters, (in general, the parameters are enclosed in parentheses).

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.