外部"C"如何显示?在C ++中工作? [英] How does extern "C" work in C++?

查看:87
本文介绍了外部"C"如何显示?在C ++中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件的开头看到使用C2的C ++代码,如下所示:

I see some code in C++ using extern "C" at the beginning of the file like this:

#ifdef __cplusplus 
extern "C" {} 
#endif

这是什么意思?如何运作?

What does this mean? How does it work?

推荐答案

可能不是这样,而更像是:

It's probably not like that, but more like:

#ifdef __cplusplus 
extern "C" {
#endif

//some includes or declarations

#ifdef __cplusplus 
}
#endif

它告诉编译器对指令内声明的内容使用C名称修饰.

It tells the compiler to use C name mangling for whatever is declared inside the directives.

您现在拥有的方式:

#ifdef __cplusplus 
extern "C" {} 
#endif

只是无效代码.

这篇关于外部"C"如何显示?在C ++中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆