C/C++混合编程 —— extern "C" 的用法

本文介绍了在C++中如何使用extern "C"来调用C的函数,以解决编译错误。通过示例代码,展示了不使用extern "C"声明时可能出现的问题,并提供了相关C++标准的引用和外部资源链接,帮助理解这一关键概念。
摘要由CSDN通过智能技术生成

2012-01-03 wcdj

Question:

What's the theory behind this: #ifdef __cplusplus extern "C" {     
I have been meeting the following in some c/c++ codes but I don't understand the theory behind it:
 
#ifdef __cplusplus
extern "C" {
#endif
 
I want to understand how it works. I know about the preprocessing but I don't know what that extern "C" in the code does. Someone teach me please!

Answers 1:

The C++ compiler does something called name mangling which facilitates function overloading.
The extern "C" syntax tell the C++ compiler not to perform function overloading.
The code snippet that you posted first checks if the code being compiled is using a C++ compiler and if so starts a block in which name mangling will not be done.

Answer 2:

That typically encloses DLL's exported
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值