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 about vectors in c ++?

681


What is problem with overriding functions?

676


What is code reusability in c++?

778


What is a Default constructor?

1067


Write syntax to define friend functions in C++.

702






What is a responder chain?

654


Which bitwise operator is used to check whether a particular bit is on or off?

682


How a macro differs from a template?

766


What is istream and ostream in c++?

697


Why do we learn c++?

622


What are the benefits of operator overloading?

787


When should we use container classes instead of arrays?

675


What is the use of 'using' declaration in c++?

721


What is the best ide for c++?

674


Differentiate between declaration and definition.

679