Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!att!att!drutx!ldg@drywit.ATT.COM From: ldg@drywit.ATT.COM (XGPB30000-GibbonsD(DRR6702)262) Newsgroups: comp.lang.c++ Subject: Re: calling C++ from C Message-ID: <8258@drutx.ATT.COM> Date: 19 Apr 91 18:54:13 GMT References: <1991Apr15.154120.13484@murdoch.acc.Virginia.EDU> Sender: news@drutx.ATT.COM Reply-To: ldg@drywit.ATT.COM Lines: 33 From article <1991Apr15.154120.13484@murdoch.acc.Virginia.EDU>, by pts@faraday.clas.Virginia.EDU (Paul T. Shannon): > Though many books explain how to call C functions from C++, I'm > having difficulty figuring out how to do the opposite. > > I have a large C program, built from several modules of Ansi C > code. I want to add two C++ modules to this, and call the member > functions from the C program. > > Do I have to determine how my compiler (Turbo C++ version 1.01) > mangles names, and then call the member functions with those > names? C++ provides a mechanism for this. In your C++ program you provide something like extern "C" void CallableFromC() { // your C++ code here } The above function has "C" linkage, which in implementation terms means its name is not mangled. Invoking member functions from C is a bit trickier - wrap each call in a function as above to avoid the mangling issues. -- -------------------------------------------------------------------------------- -- Doug Gibbons | ldg@druhi.ATT.COM or att!druhi!ldg -- AT&T Bell Laboratories -- Denver CO