# Ifdef _ cplusplus extern "C" {# endif // a piece of code # ifdef _ cplusplus} # endif

Source: Internet
Author: User
What does this code mean? First, __cplusplus is the custom macro in CPP. If this macro is defined, it indicates that this is a piece of CPP Code. That is to say, the above Code indicates: if this is a piece of CPP Code, add "extern" C "{" and "}" to process the Code. The Code inside {} is processed through extern "C. To understand why extern "C" is used, you must start with the overload processing of functions in CPP. In C ++, in order to support the overload mechanism, some processing should be performed on the function name in the compilation code, such as the return type of the function. in C, it is just a simple function name and no other information is added. that is to say, C ++ and C process the name of the generated function differently.
When designing C ++, the father of C ++ considered that a large number of C Code existed at that time. In order to support the original C code and write the C library, to support C as much as possible in C ++, extern "C" is one of the strategies. Therefore, to call the library file written in C ++ code, we need to use extern "c" to tell the compiler: This is a library file written in C, please use the C method to link them.
# Endif in this {} corresponds to # ifdef-cplusplus above, # ifdef-cplusplus corresponds to the final # endif, # ifdef and # endif always correspond one to one, indicates the start and end of Conditional compilation.

# Ifdef _ cplusplus extern "C" {# endif // a piece of code # ifdef _ cplusplus} # endif

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.