天资愚钝,没有祥加指点参不透。
c++与c的编译器不同. c++对符号(你可以简单理解为函数名, 变量名等)会做一些修改.
用 extern "C" 就是告诉c++编译器不要修改符号命名
同意 realdreamer(楼主英明,贫僧久仰大名,特来拜见)
extern "C" 就是告诉c++编译器不要修改符号命名,以C原来的函数或变量符号输出!!!!
Mixed-Language Programming with C++
Home | Overview | How Do I
C++ uses the same calling convention and parameter-passing techniques as C, but naming conventions are different because of C++ decoration of external symbols. By causing C++ to drop name decoration, the extern "C" syntax makes it possible for a C++ module to share data and routines with other languages.
The following example declares prn as an external function using the C naming convention. This declaration appears in C++ source code.
extern "C"
{
void prn();
}
To call functions written in Fortran (or MASM), declare the function as you would in C and use a "C" linkage specification. For example, to call the Fortran function FACT from C++, declare it as follows:
extern "C" { int __stdcall FACT( int n ); }
The extern "C" syntax can be used to adjust a call from C++ to other languages, or to change the naming convention of C++ routines called from other languages. However, extern "C" can be used only from within C++. If the C++ code does not use extern "C" and cannot be changed, you can call C++ routines only by determining the name decoration and generating it from the other language. You can always determine the decoration by using the DUMPBIN utility. Use this approach only as a last resort, because the decoration scheme is not guaranteed to remain the same between versions.
Use of extern "C" has some restrictions:
You cannot declare a member function with extern "C".
You can specify extern "C" for only one instance of an overloaded function; all other instances of an overloaded function have C++ linkage.
For more information on the extern "C" linkage specification, seeLinkage Specifications in C++ Language Reference.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.