Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I create a C++ function f(int,char,float) that is callable by my C code?

0
Posted

How can I create a C++ function f(int,char,float) that is callable by my C code?

0

The C++ compiler must know that f(int,char,float) is to be called by a C compiler using the extern C construct: // This is C++ code // Declare f(int,char,float) using extern C: extern “C” void f(int i, char c, float x); // … // Define f(int,char,float) in some C++ module: void f(int i, char c, float x) { // … } The extern C line tells the compiler that the external information sent to the linker should use C calling conventions and name mangling (e.g., preceded by a single underscore). Since name overloading isn’t supported by C, you can’t make several overloaded functions simultaneously callable by a C program.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.