找回密码
 注册
搜索
查看: 1606|回复: 7

[讨论] C中怎么extern C++

[复制链接]
发表于 2011-5-16 17:25:15 | 显示全部楼层 |阅读模式
请教高手如何在C中调用C++的函数
发表于 2011-5-17 09:08:59 | 显示全部楼层
学习了!!
点评回复

使用道具 举报

发表于 2011-5-16 19:47:22 | 显示全部楼层
告诉C编译器,当遇到C++代码的时候按照C的方式编译。
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

/* extern API ,变量等*/
#ifdef __cplusplus
}   /* extern "C" */
#endif
点评回复

使用道具 举报

发表于 2011-5-17 12:46:29 | 显示全部楼层
学习了,见过这样用法
点评回复

使用道具 举报

发表于 2011-8-1 13:50:54 | 显示全部楼层
还是学习一下吧
点评回复

使用道具 举报

发表于 2011-7-26 11:42:00 | 显示全部楼层
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

/* extern API ,变量等*/
#ifdef __cplusplus
}   /* extern "C" */
#endif

本文来自:我爱研发网(52RD.com) - R&D大本营
详细出处:http://www.52rd.com/bbs/Detail_RD.BBS_208734_15_1_1.html
点评回复

使用道具 举报

发表于 2011-8-9 23:16:34 | 显示全部楼层
这个主要是在link阶段其作用的。
告诉C++编译器,当遇到extern "C"标注的代码时,采用了C语言的命名方式,
不对名字进行特殊处理(C++支持函数重载,所以需要特殊处理)。
告诉连接器这些函数都采用了C语言的命名方式,所以不管是C调用(只能按照C语言的命名方式)还是C++调用都按照C语言的命名方式查找连接。
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

/* extern API ,变量等*/
#ifdef __cplusplus
}   /* extern "C" */
#endif
点评回复

使用道具 举报

发表于 2011-8-3 17:44:35 | 显示全部楼层
那应该是C++调用C的方法。
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-10-6 22:19 , Processed in 0.048694 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表