Han M
Han M

Reputation: 399

Do C++ and C use the same kind linker?

As the title asks, do C++ and C use the same kind linker in the linking process? Also, for the compilers of C++ and C, does the C++ compiler built upon the C compiler?

Upvotes: 5

Views: 810

Answers (1)

user2100815
user2100815

Reputation:

Both implementations use the same linker. However, C++ must encode the names and types of the things being linked, in order to support function overloading, so that they cannot be linked with the wrong function. So, if you have two C++ functions like this:

 void func( int );
 void func( int, double);

then the C++ compiler will generate names for these functions something like func_int and func_int_double. Exactly what names are generated is compiler specific, and is not specified by the C++ Standard. As C doesn't support overloading, no such mechanism is needed in C, but you do need to turn off this so-called name-mangling if you want to link C++ code with C, which is what the extern "C" construct does.

Upvotes: 9

Related Questions