Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

07
Dec

How can I call a C function f(int,char,float) from my C++ code?

Related Blog Items

If you have an individual C function that you want to call, and for some reason you don’t have or don’t want to #include a C header file in which that function is declared, you can declare the individual C function in your C++ code using the extern “C” syntax. Naturally you need to use the full function prototype:

extern ”C” void f(int i, char c, float x);

A block of several C functions can be grouped via braces:

extern ”C” {
void   f(int i, char c, float x);
int    g(char* s, const char* s2);
double sqrtOfSumOfSquares(double a, double b);
}

After this you simply call the function just as if it were a C++ function:

int main()
{
f(7, ’x', 3.14);   // Note: nothing unusual in the call

}
source:USENET
[tags]mixing c & c++ code[/tags]

Popularity: 7%

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