开发者

extern keyword in c [duplicate]

开发者 https://www.devze.com 2023-02-20 13:15 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Why do we need extern “C”{ #include <foo.h> } in C++?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Why do we need extern “C”{ #include <foo.h> } in C++?

many a times in our code i have seen some statements like following:

extern "C" {

//some code

     开发者_StackOverflow   }; 

what does this exactly mean?


It tells the C++ compiler that "some code" must be compiled in C style. This allows the linkage between C and C++ code.


It tells the compiler to treat the following code as C code and not as c++ code


More to the point, functions with C++ linkage will not be found by the linker when called from a C function unless you specify that the functions should have the same linkage type. So you'll get all sorts of link errors, which won't seem obvious as to why.

0

精彩评论

暂无评论...
验证码 换一张
取 消