Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!think.com!mintaka!snorkelwacker.mit.edu!thunder.mcrcim.mcgill.edu!bonnie.concordia.ca!s3!robert From: robert@ireq.hydro.qc.ca (R.Meunier 8516) Newsgroups: comp.lang.c++ Subject: mixing c++ and c - SUMMARY Message-ID: <5279@s3.ireq.hydro.qc.ca> Date: 6 Feb 91 22:03:38 GMT Sender: root@s3.ireq.hydro.qc.ca Reply-To: robert@ireq.hydro.qc.ca () Organization: IREQ, Hydro-Quebec, QC, Canada Lines: 57 Contrary to what most people think, it is possible to mix c++ function with c. Here is how i have done it. ------------------------------------------------------------- class A { private: int i; public: A(int); int inc(); } A::A(int ii) { i=ii; } A::inc() { return(++i); } caddr_t newA(int ii) { return(new A(ii)); } int incA(A *a) { return(a->inc()); } ------------------------------------------------------------- That code is compile with a c++ compiler and put in a library If i need that class in a standard c program, i call only the function newA() and incA(). Their name is not mangle since they are standard function. The c++ library libC.a as to be provide to the compiler and someone have mention by mail that the function _main() as to be called manually to initialise static variables in classes. I did not search very much but 'cout' were crashing my program, since i didn't need them, i took them out. Thank you to everyone who have replied -- Robert Meunier Institut de Recherche d'Hydro-Quebec Ingenieur 1800 Montee Ste-Julie, Varennes Internet: robert@ireq.hydro.qc.ca Qc, Canada, J3X 1S1 maintainer: BASIC mailing list request to basic-request@ireq.hydro.qc.ca