You normally don’t have to worry about name mangling. But you should know what it is.

This sounds a lot worse than it is. Name mangling is a technique that compiler vendors use to give overloaded methods unique names. It’s also sometimes called name decoration. You’ll likely see strange names that don’t match what you might expect when debugging or when trying to understand linker errors.

Before C++ or other languages that allow you to create methods with the same name, each method had to have a unique name. It’s easy to take for granted this ability to name methods with the same name. At some point though, the compiler needs to know exactly which method will be called. And the linker also needs to be able to identify one method from another. We can’t use a simple method name for this when that’s not unique.

What most languages do is enforce that the method name along with other factors such as the parameter types is unique. At least that’s what we see when programming. But behind the scenes, the compiler renames methods by using combinations of the method name, special characters, the parameter types, and possibly the calling convention, return type, class name, and other factors. It’s not a very readable name. And there’s no standard way that compilers follow. They’re all different even sometimes between versions.

Sometimes, the name mangling will be standardized. This is usually for simple languages like C so that different compiler vendors can make operating system calls. Yes, even the C language that doesn’t allow method overloading can benefit from name mangling to be able to distinguish how a method should be called. this is called the method calling convention.

Listen to the episode for more details including why compiler vendors don’t just agree on a standard naming system.