您的位置:首页 > 其它

Understanding of extern "C"

2012-01-01 18:08 190 查看
In this example, there are two files, namely f1.c and test.cc.

f1.c

void f1()
{
return;
}


test.cc

extern "C" {
extern void f1();
}

int main()
{
f1();
return 0;
}


Compiler will compile the source code according to the format of the files. Provided that extern "C" is not used, function f1 in f1.c will be a short name compared to a long name in test.cc in assemble language due to overload in C++. With extern "C", developers
can use C in C++.

We can make C style compile in .cpp or .cc files by extern "C".

f2.cc

extern "C" {
void f2()
{
return;
}
}


test.cc

extern "C" {
extern void f2();
}

int main()
{
f2();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: