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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / guest

By using the keyword ?extern?

Is This Answer Correct ?    23 Yes 7 No

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

Answer / nikhil upadhyay

By using the extern "C" linkage specification around the C function declarations.
Programmers should know about mangled function names and type-safe linkages. Then they should explain how the extern "C" linkage specification statement turns that feature off during compilation so that the linker properly links function calls to C functions. Another acceptable answer is "I don't know. We never had to do that." Merely describing what a linker does indicates that the programmer does not understand the issue that underlies the question.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / prabakaran

including the header file #include<stdio.h>

Is This Answer Correct ?    3 Yes 20 No

Post New Answer

More C++ General Interview Questions

Show the application of a dynamic array with the help of an example.

0 Answers  


What do you mean by overhead in c++?

0 Answers  


When should you use multiple inheritance?

2 Answers  


Explain shallow copy?

0 Answers  


If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

0 Answers  






Explain what is class definition in c++ ?

0 Answers  


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

0 Answers  


How can a '::' operator be used as unary operator?

1 Answers  


How to declare a function pointer?

0 Answers  


What is near, far and huge pointers? How many bytes are occupied by them?

0 Answers  


Why c++ is faster than java?

0 Answers  


Can the creation of operator** is allowed to perform the to-the-power-of operations?

0 Answers  


Categories