Defining C functions in .cpp file

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
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.
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.