Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!ubitrex.mb.ca!dab From: dab@ubitrex.mb.ca (Danny Boulet) Newsgroups: comp.lang.c++ Subject: Re: call C++ from C Keywords: C++/C Message-ID: <1991Jun28.153143.5476@ccu.umanitoba.ca> Date: 28 Jun 91 15:31:43 GMT References: <359@soleil.jupiter.UUCP> <20463@alice.att.com> Sender: news@ccu.umanitoba.ca Organization: Ubitrex Corporation, Winnipeg, Manitoba, Canada Lines: 51 In article <20463@alice.att.com> ark@alice.UUCP () writes: >In article <359@soleil.jupiter.UUCP> rh@jupiter.UUCP (#Rachid Himmi) writes: > >> I'm looking for the way to call a C++ module from a C program through >> the declaration of a class and the call of its function members. In your C++ code, write C callable functions that invoke the C++ members. For example: ---------------------- C++ code ------------------------ class fred { public: . . . int doit(int x); . . . }; extern "C" int freddoit(void *ptr,int x) { fred *p = (fred *)ptr; return( p->doit(x) ); } ---------------------------------------------------------- Call "freddoit" from C with a pointer to an instance of "fred" as the first parameter and (in this example) an appropriate value for "x" as the second parameter: ---------------------- C code ---------------------------- w = freddoit(fredptr,124); ---------------------------------------------------------- I've no idea if this is supposed to work but it does for me. > >Turn your C program into a C++ program and it's easy. >Otherwise, it's a matter between you and your implementer(s) >and it's not guaranteed to work no matter what you do. >-- > --Andrew Koenig > ark@europa.att.com