comp.lang.ada
 help / color / mirror / Atom feed
From: Yves Bailly <kafka.fr@laposte.net>
Subject: C++ from Ada, again
Date: Fri, 19 May 2006 00:08:25 +0200
Date: 2006-05-19T00:08:26+02:00	[thread overview]
Message-ID: <446cee4e$0$5159$626a54ce@news.free.fr> (raw)

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 | //\
\_/ |                                      | \_/`




             reply	other threads:[~2006-05-18 22:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-18 22:08 Yves Bailly [this message]
2006-05-19  9:19 ` C++ from Ada, again news.hinet.net
2006-05-19 10:50   ` Yves Bailly
2006-05-20 15:12 ` Yves Bailly
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox