Name Mangling and extern “C” in C++

发布时间 2023-07-31 11:38:38作者: huorexiaji

Since C++ supports function overloading, additional information has to be added to function names (called Name mangling) to avoid conflicts in binary code. 2. Function names may not be changed in C as it doesn't support function overloading. To avoid linking problems, C++ supports the extern “C” block.

C++ supports function overloading, i.e., there can be more than one function with the same name but, different parameters. How does the C++ compiler distinguish between different functions when it generates object code – it changes names by adding information about arguments. This technique of adding additional information to function names is called Name Mangling. C++ standard doesn’t specify any particular technique for name mangling, so different compilers may append different information to function names.