//#ifdef __cplusplus extern "C" 含义
来源:互联网 发布:淘宝店铺简介模板 编辑:程序博客网 时间:2024/05/18 00:44
#ifdef __cplusplus
extern "C" {
#endif
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController
@property (nonatomic,readonly) UIView *headView;
@end
//#ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
//这样的代码到底是什么意思呢?首先,__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总是一一对应的,表明条件编译开始和结
#ifdef __cplusplus
}
#endif
- //#ifdef __cplusplus extern "C" 含义
- #ifdef __cplusplus extern "C" { #endif 含义
- #ifdef __cplusplus extern "C" {
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern “C”
- #ifdef __cplusplus extern "C" { #endif”的定义的含义
- #ifdef __cplusplus extern "C" { #endif”的定义的含义
- #ifdef __cplusplus extern "C" { #endif”的定义的含义 .
- #ifdef __cplusplus extern "C" { #endif”的定义的含义
- #ifdef __cplusplus extern “C” #endif
- 关于#ifdef __cplusplus extern C
- #ifdef __cplusplus extern "c" { #endif
- #ifdef __cplusplus extern "C" { #endif
- #ifdef __cplusplus extern "C" 笔记
- Final、finally、finalize区别
- BZOZ 1511: [POI2006]OKR-Periods of Words KMP
- scanf和%s,%c的精巧区别
- HashMap 和 Hashtable 有什么区别?
- mybatis的Sql语句打印
- //#ifdef __cplusplus extern "C" 含义
- Java技术——你真的了解String类的intern()方法吗
- Dubbo(1)
- 1~9分成1:2:3的三个三位数
- poj1182食物链(带权并查集)
- 在visual studio中使用共享程序集的方法
- 利用纯css做选项卡源码
- 图像处理去噪点(中值滤波)java
- Mysql之in和Exists的用法