#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"的更多相关文章

  1. #ifdef __cplusplus extern "C" { #endif

    1.在好多程序中我们会遇到下面代码段 #ifdef __cplusplus        extern "C" {        #endif //c语法代码段 #ifdef __ ...

  2. 几乎每个文件里面都有 #ifdef __cplusplus extern "C" { #endif 可我没找到程序里那个地方定义了__cplusplus 啊?这又是怎么回事呢?

    我们的C语言有个进化版,叫C++,这个想必楼主知道,Keil MDK是支持C++编程的,也就是说,你可以用C语言或者C++写你的程序,都可以. 但是,有一个问题,就是头文件的问题,C语言写的头文件C+ ...

  3. #ifdef __cplusplus extern c #endif 的作用

    #ifdef __cplusplus // C++编译环境中才会定义__cplusplus (plus就是"+"的意思) extern "C" { // 告诉编 ...

  4. “#ifdef __cplusplus extern "C" { #endif”的定义

    平时我们在linux c平台开发的时候,引用了一些Cpp或者C的代码库,发现一些头文件有如下代码条件编译. #ifdef __cplusplus extern "C" { #end ...

  5. #ifdef __cplusplus extern "C" {代码} 倒底是什么意思?

    时常在cpp的代码之中看到这样的代码: #ifdef __cplusplus   extern "C" { #endif //一段代码 #ifdef __cplusplus } # ...

  6. “#ifdef __cplusplus extern "C" { #endif”的定义-----C和C++的互相调用

    "#ifdef __cplusplus extern "C" { #endif"的定义 看一些程序的时候老是有 "#ifdef __cplusplus ...

  7. #ifdef __cplusplus extern "C" { #endif”的定义

      平时我们在linux c平台开发的时候,引用了一些Cpp或者C的代码库,发现一些头文件有如下代码条件编译. #ifdef __cplusplus extern "C" { #e ...

  8. 【转】#ifdef __cplusplus+extern "C"的用法

    时常看到别人的头文件中,有这样的代码: #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #en ...

  9. #ifdef __cplusplus extern "C" { #endif 含义

    转载! 1.在好多程序中我们会遇到下面代码段 #ifdef __cplusplus         extern "C" {         #endif //c语法代码段 #if ...

随机推荐

  1. mount命令

    注:硬件设备由linux系统自动识别,但必须成功挂载后才能使用 mount #查询已挂载 mount -a #依据配置文件/etc/fstab的内容自动挂载 挂载命令格式: mount  [-t 文件 ...

  2. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  3. 一种json生成html的思路

    输入: [{ tag:"ul", attribute:{ class:"father6" }, property:{ className:"fathe ...

  4. 工程源码github地址

    APP APP历史版本地址:https://github.com/Myskety/aps APP最终版地址:https://github.com/dycaly/YHAPP 服务器 历史服务器版本地址: ...

  5. struts2 if标签示例

    下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...

  6. shiro-web整合

    1.所需要jar <!-- shiro核心包 --> <dependency> <groupId>org.apache.shiro</groupId> ...

  7. Python学习(2)基本语法

    目录 交互式编程 脚本式编程 Python 标识符 Python保留字符 行和缩进 多行语句 Python 引号 Python注释 Python空行 python的输入和输出 命令行参数 交互式编程 ...

  8. css+JS实现遮罩弹框

    <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta nam ...

  9. lmdb存储的一些库相关函数

    MDB_env 为一个结构体,Opaque structure for a database environment. MDB_txn :Opaque structure for a transact ...

  10. TensorFlow Playground

    A Neural Network Playground Understanding neural networks with TensorFlow Playground 机器之心翻译