comp.lang.ada
 help / color / mirror / Atom feed
* C++ from Ada, again
@ 2006-05-18 22:08 Yves Bailly
  2006-05-19  9:19 ` news.hinet.net
  2006-05-20 15:12 ` Yves Bailly
  0 siblings, 2 replies; 4+ messages in thread
From: Yves Bailly @ 2006-05-18 22:08 UTC (permalink / 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 | //\
\_/ |                                      | \_/`




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-05-20 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-18 22:08 C++ from Ada, again Yves Bailly
2006-05-19  9:19 ` news.hinet.net
2006-05-19 10:50   ` Yves Bailly
2006-05-20 15:12 ` Yves Bailly

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