What is 'Name Mangling', and why is extern "C" necessary when linking with C code?

Last updated 21 June 2026

  • Name mangling encodes a function's namespace, class, and parameter types into its linker symbol so overloads like foo(int) and foo(double) get distinct symbols. The scheme is compiler-specific.

  • C does not overload and emits plain names, so extern "C" disables mangling to make C++ look up the C symbol. Without it you get unresolved-symbol link errors.

  • https://learn.microsoft.com/en-us/answers/questions/1161386/unresolved-external-symbol-c-(not-c-)
All C++ interview questions