Ada 95 Software Interoperating with C++

Here is a copy of a news article by Tom Quiggle of SGI which describes the demonstration for TRI-Ada 94 that he built.
Date: Fri, 18 Nov 1994 23:09:32 +0000 (GMT)
From: quiggle@lovelace.wpd.sgi.com (Tom Quiggle)
Subject: Re: SGI inheriting C++ classes ...
Organization: Silicon Graphics, Inc.  Mountain View, CA
Newsgroups: comp.lang.ada
Lines: 91
Nntp-Posting-Host: lovelace.wpd.sgi.com
References: <2ECBCF25@SMTPGATE2.STRATCOM.AF.MIL>

In article <2ECBCF25@SMTPGATE2.STRATCOM.AF.MIL>, "Bennett, Chip writes:
> Recently, in info-ada, David Weller made a reference to "... SGI's cool
> demonstration of inheriting from C++ classes ...", that from the context, I
> assume means inherited by Ada 9X.

Your assumption is basically correct.

> What is that all about.  Did SGI demo the ability to fully inherit C++
> classes by Ada 9X at TRI-Ada?

Let me first respond to the general issue of Ada9x interfacing to C++ classes,
then describe the specifics of the demo we were showing at TriAda.

-------------------

As has been widely publicized, SGI's Ada9x product strategy is based on
a commercially supported version of the GNAT, integrated with SGI's
multilinguial software development environment.  Following detailed
design discussions with SGI, the GNAT team (and specifically Cyrille
Comar) has added several implementation-defined pragmas to the GNAT to
facilitate interfacing to C++ classes from Ada.

C++ classes with virtual member functions are represented as Ada9x
tagged types.  With pragma advice, the GNAT will layout the tagged type to 
exactly correspond to the layout of the C++ class (including the C++ virtual
function table).  The C++ member functions,virtual and non-virtual, are
imported in the usual manner with Pragma Import.  For virtual member functions,
there is an additional pragma to specify which vtable pointer and index to
use in generating dispatching calls (I say which vtable pointer because in
the case of a C++ class with multiple base classes, you may have more than
one vtable pointer to dispatch off of).

The net result is that C++ classes and objects may be directly imported
into Ada9x programs.  In addition to directly using a C++ class, an Ada
application can derive off of a C++ class and:

   - add a record extension part  (i.e. add new member data)
   - add new primitive oparations (i.e. add new member functions)
   - override C++ virtual functions with Ada implementations

Objects of a C++ class type (or type derived from such a type) may be declared
in Ada and operated on by either Ada subprograms or C++ member functions.  Since
such objects share a common virtual-function/dispatch table, either language can
dispatch calls to operations defined in the other language.  All of this has
been demonstrated with both SGI's C++ compiler and the GNU C++ compiler (G++).

To aid in building Ada interfaces to C and C++ libraries, SGI is
developing a tool capable of reading C/C++ header files and generating
corresponding Ada package specifications.  The binding generator
produces the appropriate implementation defined pragmas for specifying
the layout of C++ classes, as well as the necessary mangled linknames
for C++ member functions.  The tool will also drop out-of-line bodies for
in-line member functions (which have no callable body in a the compiled C++
object code), and perform other minor miracles.     :-)

--------------

All of which leads me to Puck...

SGI offers OpenInventor, an object-oriented, interactive, 3D modeling and
rendering library consisting of ~200 classes in as many header files.  The
inventor team produced a superb C++ example program in the form of an
interactive game resembling ice hocky.

In the week preceding TriAda (actually in just over 4 days), I
translated the main program of Puck to Ada9x, and generated slightly
more than 38000 lines of Ada bindings to (a subset) of the OpenInventor
header files needed by Puck.  The result was a mixed language
application in which the highest level objects in the system were
declared in Ada, and implemented in C++.  In this specific example, no
derivation (subclassing) was performed on the Ada side.  As time
permits, and I rewrite more of the Puck application code in Ada, this
will change.

> Thanks,

No problem.  If you have further questions, feel free to contact me
directly.

> *****************************************************************
> * Chip Bennett, GDE Systems Inc | BennettC@j64.stratcom.af.mil  *
> * USSTRATCOM/J64213             | Voice (402)294-7360           *
> * 901 SAC Blvd, Suite 2B24      | FAX   (402)294-7912           *
> * Offutt AFB, NE 68113-6600     | Proud member of Team Ada      *
> * Opinions expressed here are my own _so_,  TTFWTW              *
> *****************************************************************

------
Tom Quiggle                                                quiggle@sgi.com
Silicon Graphics                                           (415) 390 - 2884