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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dc678c047f29ac37,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!news2.volia.net!solnet.ch!solnet.ch!proxad.net!cleanfeed1-b.proxad.net!nnrp11-1.free.fr!not-for-mail Message-Id: <446cee4e$0$5159$626a54ce@news.free.fr> From: Yves Bailly Subject: C++ from Ada, again Newsgroups: comp.lang.ada Date: Fri, 19 May 2006 00:08:25 +0200 User-Agent: KNode/0.10.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8Bit Organization: Guest of ProXad - France NNTP-Posting-Date: 19 May 2006 00:08:26 MEST NNTP-Posting-Host: 81.56.171.53 X-Trace: 1147990106 nnrp11-1.free.fr 8110 81.56.171.53:58754 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:4300 Date: 2006-05-19T00:08:26+02:00 List-Id: Hello all, Here's a new try to call C++ from Ada, while keeping as most as possible the OOP semantic. The code: http://kafka-fr.hd.free.fr/~yves/cpp_ada.tar.bz2 Now a bit of explanation. Two classes are declared in C++, "Base" and "Derived", containing a normal method and a virtual method. The virtual method is overdefined into "Derived". The trick is to create a kind of "double-wrapper". The class "Wrapper" contains only a "void*" pointer, to receive the address of an Ada object (Jeffrey told System.Address are not equivalent to C pointer, but I saw it too late - sorry, I'll do better next time). Then a class "Base_Wrapper" is created, derived from both "Wrapper" and "Base". It overdefine the virtual method, to call an exported Ada procedure. Then C functions wrappers are created for each of the method of "Wrapper_Base", just forwarding the call to the corresponding method of "Base". Those functions take "Wrapper_Base" pointers. The Ada procedure calls another *imported* procedure, which itself corresponds to the C wrapper just mentioned. Why so much trouble ? Here's the nice part. If I create a new *Ada* type derived from the "Base" type, then thanks to polymorphism in both Ada and C++ the overdefined virtual procedure is actually called. Sorry if I'm not clear, english is not my native language. Please, have a quick look at the code, and tell me. For what I can tell, it uses only standard features, and therefore should be portable among compilers (when System.Address are changed to something always equivalent to C pointers). Thanks for your patience and best regards, -- (o< | Yves Bailly  : http://kafka-fr.net   | -o) //\ | Linux Dijon  : http://www.coagul.org | //\ \_/ |                                      | \_/`