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