Defining C functions in .cpp file

Jul 2, 2010 at 7:07pm
Hello Experts,

My requirement is to call a 'C' function from a .cpp file and I want to define that function in the same .cpp file.

To achieve this:
I have enclosed the 'C' function declaration within the extern "C" construct in the .cpp file

Question:
Is it necessary to enclose even the function definition within the extern "C" construct.


Thanks and regards
Ravi
Jul 2, 2010 at 7:51pm
Only if the function is defined in a C++ source file. If the function is defined in a C source file, the C compiler will compile it, and of course no name mangling will occur.
Jul 2, 2010 at 8:07pm
The function should be declared within an extern "C" block in the header file.
At the point of implementation, in the C++ file, the compiler should see the declaration
(be sure to include the header for it) and then the answer to your question is no.
Topic archived. No new replies allowed.