Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!purdue!mentor.cc.purdue.edu!pur-ee!pc.ecn.purdue.edu!filoj From: filoj@pc.ecn.purdue.edu (Jeffrey J Filo) Newsgroups: comp.lang.c++ Subject: Re: Using C++ AND C together Message-ID: <1272@pc.ecn.purdue.edu> Date: 14 Sep 89 15:32:03 GMT References: <953@ncratl.Atlanta.NCR.COM> <6590251@hplsla.HP.COM> <6497@columbia.edu> Reply-To: filoj@pc.ecn.purdue.edu.UUCP (Jeffrey J Filo) Organization: Purdue University Engineering Computer Network Lines: 33 In article <6497@columbia.edu> kearns@cs.columbia.edu writes: > >Is it possible to link a C program with a C++ library? >The only a priori problem I could see is that the c++ global >constructors would not be properly inited. In my research in solid modeling, I have had success linking C++ routines with C and even FORTRAN code. The way I approach it is to write a number of C functions that "turn around" and call C++ methods. For example, if an class Curve has a method SelfIntersect the C calling function can be written as: int SelfIntersect( Curve A) { A->SelfIntersect(); } A collection of these functions can be written for the set of methods. This set of functions can be compiled into an interface library. The C and FORTRAN code calls these interface functions and accesses the C++ routines in this way. One problem is that C doesn't really know about C++ objects, but a work-around is to treat the object pointers as integers. This approach is commonly used when manipulating C structures within FORTRAN code. ------ Jeff Filo filoj@pc.ecn.purdue.edu