#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 extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif的更多相关文章
- #ifdef __cplusplus extern "C" {代码} 倒底是什么意思?
时常在cpp的代码之中看到这样的代码: #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } # ...
- #ifdef __cplusplus extern "C"
#ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif首先,__cplusplus是cp ...
- 【转】#ifdef __cplusplus+extern "C"的用法
时常看到别人的头文件中,有这样的代码: #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #en ...
- #ifdef __cplusplus extern "C" { #endif
1.在好多程序中我们会遇到下面代码段 #ifdef __cplusplus extern "C" { #endif //c语法代码段 #ifdef __ ...
- #ifdef __cplusplus extern "C" { #endif 含义
转载! 1.在好多程序中我们会遇到下面代码段 #ifdef __cplusplus extern "C" { #endif //c语法代码段 #if ...
- #ifdef __cplusplus extern "C" { #endif 的解释
好多程序中都会遇到下列代码段: #ifdef __cplusplus extern "C" { #endif /****************** C语法代码段 ******** ...
- #ifdef __cplusplus extern c #endif 的作用
#ifdef __cplusplus // C++编译环境中才会定义__cplusplus (plus就是"+"的意思) extern "C" { // 告诉编 ...
- “#ifdef __cplusplus extern "C" { #endif”的定义
平时我们在linux c平台开发的时候,引用了一些Cpp或者C的代码库,发现一些头文件有如下代码条件编译. #ifdef __cplusplus extern "C" { #end ...
- “#ifdef __cplusplus extern "C" { #endif”的定义-----C和C++的互相调用
"#ifdef __cplusplus extern "C" { #endif"的定义 看一些程序的时候老是有 "#ifdef __cplusplus ...
随机推荐
- Django中如何查找模板
参考:http://my.oschina.net/zuoan001/blog/188782 Django的setting中有关找模板的配置有如下两个: TEMPLATE_LOADERS TEMPLAT ...
- mysql导入和导出数据
Linux下如何单个库进行导入和备份操作 1.将数据导入数据库mysql -u账号 -p密码 数据库<sql脚本 mysql -uroot -proot test</home/upload ...
- 转MYSQL学习(二) 运算符
MYSQL中的运算符很多,这一节主要讲MYSQL中有的,而SQLSERVER没有的运算符 安全等于运算符(<=>) 这个操作符和=操作符执行相同的比较操作,不过<=>可以用来判 ...
- Java for LeetCode 060 Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 【linux】awk的使用
教程来自:http://www.runoob.com/linux/linux-comm-awk.html 教程中的例子很好,可以有助于快速上手awk.但是里面的细节介绍的并不清楚. 问题1:什么时候写 ...
- [Android Pro] fragment中嵌套viewpager,vierpager中有多个fragment,不显示
referece to : http://blog.csdn.net/mybook1122/article/details/24003343 现在好多应用流行一种布局.底部几个工具栏选项,上面也有类 ...
- atom初体验
今天捣鼓了一天的atom,也测试了那个传说中绚丽的敲代码方式,感觉就是装逼利器,这里总结一下今天捣鼓的过程吧 首页,下载atom,这个在地址是:搜索 之后是安装插件,在这之前如果下载的是.exe的,那 ...
- 局域网通过ip查mac地址、通过mac地址查ip方法
sh-4.1# which arp #linux主机A /sbin/arp sh-4.1# arp -a 192.168.1.10 #主机B的IP bogon (:8t:8p::: [ether] o ...
- MQ的通讯模式
1) 点对点通讯:点对点方式是最为传统和常见的通讯方式,它支持一对一.一对多.多对多.多对一等多种配置方式,支持树状.网状等多种拓扑结构. 2) 多点广播:MQ适用于不同类型的应用.其中重要的,也是正 ...
- poj 1273 最大流入门
明天再拍一遍 #include <iostream> #include <queue> using namespace std; ; const int INF = 0x7FF ...