Javatpoint Logo
Javatpoint Logo

Name Mangling and Extern "C" in C++

Both Java and C++ programming languages support method and function overloading, respectively. Function overloading is simply having more than one function, which is differentiated either by having differences in the number of arguments or by the difference in the data types passed as arguments or parameters. The real question is how the compiler of java and c++ programming languages differentiates one function from the other.

The simple answer to a complex problem, the compiler adds more information from its end. It saves the methods or parameters to its stack memory during execution. The c++ compilers don't have any specific technique different from the others, and it uses the same name-mangling concept to solve the problem of function overloading.

Function Overloading in C++ -1

Output:

The sum of two integer variables is= 222
The sum of the two double variables is= 121.5

Function Overloading in C++ -2

Output:

The sum of two integer variables is= 430
The sum of three integer variables is= 165

Function Overloading in C++ -3

Output:

 Here we have the integer  100
 Here we have the float 100.1
 Here we have the character hundred

Name Mangling and Extern 'C' in C++

Demonstration code

Output:

/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status

C++ code

Output:

/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status

Extern C

Output:

javaTpoint






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA