[英]Use of Extern keyword
我熟悉extern关键字,它用于声明存在于其他文件中的变量,但是以下语句是什么意思?
extern "C" const IMAGE_DOS_HEADER __ImageBase;
It means the __ImageBase
global variable uses C linkage and that its name should be mangled using the rules for C instead of C++. 这意味着__ImageBase
全局变量使用C链接 ,并且它的名字应该被错位使用的C而不是C规则++。
EDIT: It just so happens that Raymond Chen recently published an article that demonstrates my original answer was plain wrong: extern "C"
does not disable name mangling, it only changes the rules used to perform it. 编辑:碰巧的是, 雷蒙德·陈(Raymond Chen)最近发表了一篇文章 ,证明我的原始答案是完全错误的: extern "C"
不会禁用名称修饰,它只会更改用于执行名称修饰的规则 。 C names can be mangled too. C名称也可以修改。
It means do not mangle the symbol name __ImageBase
that follows the extern "C"
. 这意味着不要__ImageBase
符号“ __ImageBase
extern "C"
__ImageBase
的符号extern "C"
。 In short it ensures you can use the variable in C++ code. 简而言之,它确保您可以在C ++代码中使用变量。
extern "C"
specify's the linkage to be applied. extern "C"
指定要应用的链接。 In short a Linkage specification. 简而言之,是链接规范。
It tells the C++ compiler to apply linkage of the type of C to the symbol that follows. 它告诉C ++编译器将C类型的链接应用于后面的符号。
Good Read: 读得好:
Using extern to Specify Linkage 使用extern指定链接
How to mix C and C++ 如何混合使用C和C ++
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.