Preprocessor Support for Linking to C

C++ Primer 4/e在Inherently Nonportable Features这个地方有一个单元:‘It can be useful sometimes to compile the same source file in both C or C++. The preprocessor name __cplusplus (two underscores) is automatically defined when compiling C++, so we can conditionally include code based on whether we are compiling C++.

     #ifdef __cplusplus
     // ok: we're compiling C++
     extern "C"
     #endif
     int strcmp(const char*, const char*);

中文版的这样写:‘有时候以C和C++编译同一份源码是有用的。以C++编译时,预处理器名称 __cplusplu(双底线)会被自动定义,因此我们可以根据当前是否正在进行C++编译而含入不同程式码。

#ifdef __cplusplus
//好,我们正在编译C++
extern “C”
#endif
int strcmp(const char*,const char*);

对于各种不同程式语言的连结,ㄚ琪非常的感兴趣。