是的extern" C"还需要用于链接在cpp文件用于在CFile的定义的一个全局变量? [英] Is extern "C" required also for linking global variables used in Cpp file to the one defined in a cfile?

查看:164
本文介绍了是的extern" C"还需要用于链接在cpp文件用于在CFile的定义的一个全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时的extern也需要在链接cpp文件用于在C文件中定义的全局变量C?

这是用来从它在C文件中引用,因为在C ++中的文件函数名的名字改编的C ++文件链接功能。请问C编译器也随之变化的变量??名称


解决方案

  

的externC也需要在链接cpp文件用于在C文件中定义的全局变量?


可移植的,是的。

您可能会发现,离开了的externC你的编译器的工作原理(例如,GCC,不全局命名空间裂伤C ++变量名)但是这不是你可以依靠所有的编译器。


  

请问C编译器也随之变化的变量??名称


这取决于编译器(具体地,在ABI它使用)。语言标准不指定语言级别的名称如何映射到链接器符号,因此不同的编译器可以使用不同的名称重整方案。

Is extern "C" required also for linking global variables used in Cpp file to the one defined in a c file?

It is used for linking function from C++ file which is referenced in C file because of the name mangling of function names in C++ files. Does the C compiler also changes the name of variables??

解决方案

Is extern "C" required also for linking global variables used in Cpp file to the one defined in a c file?

Portably, yes.

You might find that leaving out extern "C" works for your compiler (for example, GCC, which doesn't mangle C++ variable names in the global namespace), but that's not something you can rely on for all compilers.

Does the C compiler also changes the name of variables??

It depends on the compiler (specifically, on the ABI it uses). The language standards don't specify how language-level names map to linker symbols, so different compilers can use different name-mangling schemes.

这篇关于是的extern" C"还需要用于链接在cpp文件用于在CFile的定义的一个全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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