Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling from c to c++ functions

Status
Not open for further replies.

Ela

Programmer
Jan 9, 2001
1
IL
I need an example of a call from c to c++. Thankyou
 
In C++ you can write also C functions so:
write a c++ file containing :
class MyC {
MyC() { /* init code */ }
~MyC() { /* shut code */ }
void fun() { printf("Reached!"); }
};

extern "C" void callMyCfun()
{
MyC c;
c.fun();
}

Then, in your C interface export it like this:

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

void callMyCfun();

#ifdef __cplusplus
}
#endif /* __cplusplus */

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top