2

I have started learning C++. i came across one of the use case like below but could not explore it more. please let me know your views.

extern "C" {
    #include "file1.h"
    #include "file2.h"
}
user4581301
  • 33,082
  • 7
  • 33
  • 54
swathi
  • 21
  • 2
  • Note that this is a mistake if `file1.h` or `file2.h` include any standard headers, even indirectly – M.M May 24 '18 at 04:11

1 Answers1

0

First you should kown what is function overloading in c++ which is not in existence in c. In order to support function overloading, c++ compiler need to translate functions with the same name but different function signature into different symbol names. However, you may invoke some libs written by c++ in a c program.But because of the different function name translation mechanism,there will be some error when invoking c++-style functions in a c program. So, the extern c means i want the c++ compiler translate the function name like the c complier does.Thus it's ok to invoke c++ libs in your c program.

  • The term you are describing is often called "Name Mangling" and less often called "Name Decoration". Frankly I don't know which is official or more correct. – user4581301 May 24 '18 at 03:18
  • I have seen "Name Decoration" in some chinese books.Because of my poor English,so i described the term in my own way. –  May 24 '18 at 03:46