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

Who invented turbo c++?

0 Answers  


Differentiate between an array and a list?

0 Answers  


Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

3 Answers  


What are the different operators in C++?

3 Answers   HP,


what are the events occur in intr activated on interrupt vector table

0 Answers   HGS,






Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300

0 Answers  


What are associate containers?

0 Answers  


Why #include is used?

0 Answers  


Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

0 Answers  


Why should we use null or zero in a program?

0 Answers  


Define copy constructor.

0 Answers  


What are put and get pointers?

0 Answers  


Categories