2

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

        }; 

what does this exactly mean?

Community
  • 1
  • 1
Vijay
  • 65,327
  • 90
  • 227
  • 319
  • 1
    possible duplicate of (or rather, covered by) [Why do we need extern "C"{ #include } in C++?](http://stackoverflow.com/questions/67894/why-do-we-need-extern-c-include-foo-h-in-c) –  Mar 28 '11 at 17:27

3 Answers3

1

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

Thiago Cardoso
  • 725
  • 1
  • 5
  • 19
1

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

AsiQue
  • 21
  • 1
0

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.

stu
  • 8,461
  • 18
  • 74
  • 112