How do you link a C++ program to C functions?

Answer Posted / ravindranath m

The C++ compiler does something called as "name mangling"
for functions, while a C compiler does not. Name mangling
is a process wherein the name of the original function in a
c++ program gets changed to a new name via adding some
prefix and/or postfix to it.

As a result, a c program cannot find the required definition
when trying to link to a cpp object file.

This can be resolved by putting the following declaration in
a c++ header file that contains the cpp function declarations.
#ifdef __cplusplus
extern "C" {
#endif

// function declarations go here...
// ...

#ifdef __cplusplus
}
#endif

Is This Answer Correct ?    25 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain function overloading and operator overloading.

808


What do the keywords volatile and mean mutable?

792


Is map sorted c++?

722


What is #include iostream in c++?

769


What is a binary file? List the merits and demerits of the binary file usagein C++.

942


What is the array and initializing arrays in c++?

708


Define a pdb file.

819


Can we get the value of ios format flags?

856


What is difference between c++ 11 and c++ 14?

758


How are virtual functions implemented in c++?

794


What is a stack c++?

747


Write a program using display() function which takes two arguments.

807


What is a container class?

805


Is java the same as c++?

733


What is an iterator?

907