1957

无聊蛋疼的1957写的低端博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Why we use extern "C"

Posted on 2013-01-24 21:29  1957  阅读(160)  评论(0编辑  收藏  举报
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);
}