From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c13882a1aeb96bdb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-04 07:09:15 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: linking to C++ Date: 4 Jun 2003 07:09:14 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0306040609.60873482@posting.google.com> References: <3eddb5dd$1@baen1673807.greenlnk.net> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1054735754 15814 127.0.0.1 (4 Jun 2003 14:09:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 4 Jun 2003 14:09:14 GMT Xref: archiver1.google.com comp.lang.ada:38601 Date: 2003-06-04T14:09:14+00:00 List-Id: "Anthony Moss" wrote in message news:<3eddb5dd$1@baen1673807.greenlnk.net>... > Is there any good documentation on calling C++ functions from a piece of ADA > code. > please repond > anthony.moss@baesystems.com > > Thank you. I posted an answer to a similar question in the thread "Rational Apex Ada - Pragma interface with C++", which occured in Oct 2002. I got the idea from James Coplien's book Adanced C++ Programming Styles and Idioms. The basic idea is to bind to a factory function written in C++, and then manipulate the object from the Ada side, e.g. class X { public: void f(); }; extern "C" X* make_x() { return new (std::nothrow) X(); } extern "C" void free_x(X* p) { delete p; } extern "C" void X_f(X* x) { x->f(); } You'll need to write a binding on the Ada side, e.g. package X_Types is type X (<>) is limited private; type X_Access is access all X; pragma Convention (C, X_Access); for X_Access'Storage_Size use 0; function New_X return X_Access; procedure Free (X : in out X_Access); procedure F (X : X_Access); --or procedure F (X : access X); private type X is limited null record; end X_Types; Implement New_X, Free, and F by calling the C++ functions, which have been imported to the Ada program: package body X_Types is function C_New_X return X_Access; pragma Convention (C, C_New_X); pragma Import (C_New_X, "new_x"); //something like that function New_X return X_Access is begin return C_New_X; end; ... end X_Types; Make sure that access types are passed by *value* to the C++ function.