C编译时定义了_cplusplus,C++编译时定义了_STDC_#ifdef _cplusplus /*判断是否用C++编译器?*/ #define USING_C 0 /*是用C编译器*/ #else #define USING_C 1 /*是用C++编译器*/ #endif #include <stdio.h> int main() { if(USING_C) printf("C++\n"); else printf("C\n"); system("pause"); return 0; } 编写C与C++兼容的代码所需的宏如下:#ifdef __cplusplus extern "C" { #endif // 具体的代码 #ifdef __cplusplus } #endif
温馨提示:答案为网友推荐,仅供参考