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);
}
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);
}
相关文章推荐
- Why use sort() when we have "good old qsort()"?
- When and Why do we use "#if 0"
- Why we use stored procedure than Sql statement?
- Why we made vorlon.js and how to use it to debug your JavaScript remotely
- why should we use requset_mem_region()before using ioremap()?
- Why do we need extern “C”{ #include <foo.h> } in C++?
- what is WLAN ? when and why we need use it ?
- Why do we get error "Call to undefined function: ora_logon()/ ocilogon()"?
- what is the virtual machine, when and why we need use it ?
- sometimes we should use "disable fork" instead of "disable block_name"
- Why do we use int rather than char
- Programming Basic--why we need to add ' extern "C" ' in C++ program when calling the function which is complied by C complier?
- why we use Symbols in Hash
- Why? 在C++中调用被C编译后的函数,要在声明的前面加extern "C"
- why we use Symbols in Hash
- Why we use HTTP POST instead of HTTP GET
- Why do we use n = 16 * n + hexdigit
- NoSQL Databases, why we should use, and which one we should choose
- 我们为什么用卷积? Why should we use convolution?
- Why Do We Use Fiber Optic Switch?