您的位置:首页 > 其它

Why we use extern "C"

2013-01-24 21:29 232 查看
We often see the symbol extern "C" in C++ source files.
Why use this?
Because C++ has overload function property like:

f(int i) //defines f__Fi
f(int i ,char* j) //defines f__FiPc

When we link in other file
extern f(int); // refers to f__FI
extern f(int,char*) // refers to f__FiPc

But the C programming language's link symbol is not like this , because C don't have overload function.

int C:
f(int) // defines _f

So, if we want use C lib , we must tell the compiler the link symbol is C style.
extern "C"{
int f(int i);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: