C/C++混合编程--extern “C” 使用方法详解(二)

2014-11-24 11:40:55 · 作者: · 浏览: 5
c 还是 c++头文件,只要是想以后混合编程,就最好加上 #ifdef __cplusplus extern "C" { #endif /**** some declaration or so *****/ #ifdef __cplusplus } #endif /* end of __cplusplus */
错误的原因在于在C语言中没有关键字 extern “C”
(PS:有的人会单独使用extern "C" 来修饰某个函数,我觉得不是很好看,特别是在头文件中不能这么使用,因为在C文件中不能出现这样的关键字,所以最好使用最后介绍的条件编译 在一定条件下才使用 extern "C")