#ifdef __cplusplus代码段
来源:互联网 发布:免费手机阅读软件 编辑:程序博客网 时间:2024/06/05 05:08
#ifdef __cplusplus
extern "C" {
#endif
_CRTIMP void __cdecl _wassert(_In_z_ const wchar_t * _Message, _In_z_ const wchar_t *_File, _In_ unsigned _Line);
#ifdef __cplusplus
}
#endif
总之这段代码的含义:
如果是在c++的编译器中,对处理下面的这个函数用c编译器的方法进行处理。
c编译器和c++编译器的区别就是对重载函数的函数名的处理方式不同,c++中对重载函数名会进行处理,加上返回值、参数类型等,而c中对重载函数函数名的处理知识简单的函数名,这些不同导致对处理结果的不同,所以需要明确指出。
这样的代码到底是什么意思呢?首先,__cplusplus是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入"extern "C"{" 和 " }"处理其中的代码,其中{ }内部的代码是通过extern"C"进行处理。要明白为何使用extern"C",还得从cpp中对函数的重载处理开始说起。在c++中,为了支持重载机制,在编译生成的汇编码中,要对函数的名字进行一些处理,加入比如函数的返回类型等等.而在C中,只是简单的函数名字而已,不会加入其他的信息.也就是说:C++和C对产生的函数名字的处理是不一样的.
C++之父在设计C++之时,考虑到当时已经存在了大量的C代码,为了支持原来的C代码和已经写好C库,需要在C++中尽可能的支持C,而extern"C"就是其中的一个策略。因此,为了在C++代码中调用用C写成的库文件,就需要用extern"C"来告诉编译器:这是一个用C写成的库文件,请用C的方式来链接它们。这个{}里面的#endif对应上面的#ifdef-cplusplus,#ifdef-cplusplus对应最后的#endif, #ifdef与#endif总是一一对应的,表明条件编译开始和结束。
0 0
- #ifdef __cplusplus代码段
- #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
- #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
- #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
- #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus
- #ifdef __cplusplus是什么意思
- 关于#ifdef __cplusplus
- 关于#ifdef __cplusplus extern
- 关于“#ifdef __cplusplus”
- UITextField监听文字输入事件
- linux基础 --- grep
- Matlab 三维图像绘制(1)——纹理贴图、球体
- JavaScript中的回调函数
- ul 居中方法(兼容 IE)
- #ifdef __cplusplus代码段
- 自定义toast
- 截取HTML中代码块生成图片
- 图片翻页
- 自定义按钮(文字和图标)
- c++l类中static成员函数和成员数据变量使用
- 鸟哥的Linux私房菜(基础篇)-第零章、计算机概论(零.5)
- 滴滴柳青、58同城、美团创始人引领《财富》商界精英
- Defer, Panic, and Recover