How do you link a C++ program to C functions?
Answers were Sorted based on User's Feedback
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 |
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 |
Answer / prabakaran
including the header file #include<stdio.h>
| Is This Answer Correct ? | 3 Yes | 20 No |
What happens if an exception is throws from an, object's constructor and object's destructor?
What jobs can you get with a c++ certification?
Difference between struct and class in terms of access modifier.
Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == 4 ) y-= 7; else y = 8; Enter a segment of code (without any IF statements) that does exectly the same thing using the switch structure.
What is oops in c++?
Can c++ do everything c can?
Should I learn c or c++ or c#?
Do we have to use initialization list in spite of the assignment in constructors?
What is the role of copy constructor in copying of thrown objects?
how many rounds and wt type of questios ask in the written test for first round 2. tech. round 3. and futher rounds
What is the difference between const and constexpr?
Does c++ have a hash table?