Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

07
Dec

How can I create a C++ function that is callable by my C code?

Related Blog Items

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.

source:USENET

[tags]making a C callable function in c++[/tags]

Popularity: 5%

You need to log on to convert this article into PDF


Related Blog Items

No Comments

No comments yet.

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image