I am familiar with the extern keyword, it is used to declare a variable present in some other file, but what does the following statement mean??
extern "C" const IMAGE_DOS_HEADER __ImageBase;
I am familiar with the extern keyword, it is used to declare a variable present in some other file, but what does the following statement mean??
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++.
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. C names can be mangled too.
It means do not mangle the symbol name __ImageBase
that follows the extern "C"
. In short it ensures you can use the variable in C++ code.
extern "C"
specify's the linkage to be applied. In short a Linkage specification.
It tells the C++ compiler to apply linkage of the type of C to the symbol that follows.
Good Read:
Using extern to Specify Linkage
How to mix C and C++