1)范围:C++的语法,C中编译会报错
2) 作用:
a)告诉编译器这是一个全局的
b)告诉编译器产生类C的符号(int foo(int) c:_foo c++:_foo_int)
3) 常见写法:
extern "C" int foo(int a);
extern "C" int bar();
extern "C"
{
int foo();
int bar();
}
4)常见地点:
a)c++中调用C的lib,需要用extern "C"来修饰用到的c的头文件。
b)用c++写用来给c/c++使用的lib,也可以用extern "C"来修饰。
如果你想让你的程序使用范围更广,那就加上extern "C"吧!
PS:Test code
test.cpp
extern "C"
{
__declspec(dllexport) int foo(int a){ return 0;}
__declspec(dllexport) int bar(int a,int b){ return 0;}
}
cl /TP /LD test.cpp
使用dependency.exe可以查看生成的test.dll内部函数名