Why do we use extern "C" in C++ code?

CC++Server Side ProgrammingProgramming

You need to use extern "C" in C++ when declaring a function that was implemented/compiled in C.

Using extern "C" lets the compiler know that we want to use C naming and calling conventions. This causes the compiler to sort of entering C mode inside our C++ code. This is needed because C++ compilers mangle the names in their symbol table differently than C compilers and hence behave differently than C compilers.

Updated on 30-Jul-2019 22:30:22