The CCS #ifdef __cplusplus extern "C" {#endif Usage

When using C ++ CCS C compiler

Source

Often in CCS previous code, often appear in the .h file

#ifdef __cplusplus
extern "C"{
#endif

*一段代码

#ifdef __cplusplus
}
#endif

Code Analysis

  1. #ifdef usage
#ifdef 被定义的
	*代码
#endif

The meaning of the code above is as follows: If the definition of the "defined", then execute the code.

  1. __cplusplus
    __cplusplus is set to c ++ macros.
  2. extern "C" {}
    in C ++ in order to support overloading, the assembly code generated by the compiler, to name some processing functions, such as the return type of the function is added so on. In C, a function name only simply will not add other information. In other words: C ++ and C processing function name generated is not the same. So this statement is to execute C language statements in C ++.
  3. Overall meaning of the source code
    if the execution of the C ++ code, then extern "C" {} reputation valid, the case wherein the code is compiled manner through the C's.

To summarize

In order to perform both the code C ++, it can be performed under C.

Released six original articles · won praise 0 · Views 300

Guess you like

Origin blog.csdn.net/qq_21681077/article/details/104354817