07
Dec
How can I call a C function f(int,char,float) from my C++ code?
Related Blog Items
- How can I create a C++ function that is callable by my C code?
- Advanced Test in C: The 0x0A Best Questions for C Programmers
- C++ Advanced Tutorial - Lesson 3
- Implicit Type Conversions - part 2
- Structure padding
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);
}
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
…
}
{
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 - How can I create a C++ function that is callable by my C code?
- Advanced Test in C: The 0x0A Best Questions for C Programmers
- C++ Advanced Tutorial - Lesson 3
- Implicit Type Conversions - part 2
- Structure padding
Related Blog Items
- How can I create a C++ function that is callable by my C code?
- Advanced Test in C: The 0x0A Best Questions for C Programmers
- C++ Advanced Tutorial - Lesson 3
- Implicit Type Conversions - part 2
- Structure padding
No Comments
No comments yet.