comp.lang.ada
 help / color / mirror / Atom feed
* Ada bindings to C++
@ 1996-12-04  0:00 Brett M. Kettering
  1996-12-06  0:00 ` John Cosby
  1996-12-07  0:00 ` Joel VanLaven
  0 siblings, 2 replies; 4+ messages in thread
From: Brett M. Kettering @ 1996-12-04  0:00 UTC (permalink / raw)



I have written Ada bindings to C in both Ada 83 and Ada 95.  The
Interfaces.C package and pragma Convention of Ada 95 really make this a
lot easier.  Lately I have been considering Ada 95 bindings to C++.

Can I get some input from persons that have written Ada 95 bindings to
C++?  In my readings I have learned that the C++ class construct is
analogous to the C struct.  So, this would imply that a binding to a
class becomes an Ada 95 record that contains pointers to functions, as
well as the Ada 95 versions of C data, as its elements?  What about
class objects that are "thrown" as exceptions?

How does one go about using pragmas Import and Convention to bring these
functions into an Ada 95 program to be called?

Does the "c2ada" translator convert C++ header files to Ada 95 bindings?

Thanks for any leads.

Brett
 
--------------------------------------------------
Brett M. Kettering
LLNL   P.O. Box 808 L-493   Livermore, CA.  94550
E-mail: brettk@llnl.gov
Voice : (510) 423-3467
FAX   : (510) 422-1930
--------------------------------------------------




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

* Re: Ada bindings to C++
  1996-12-04  0:00 Ada bindings to C++ Brett M. Kettering
@ 1996-12-06  0:00 ` John Cosby
  1996-12-06  0:00   ` Robert Dewar
  1996-12-07  0:00 ` Joel VanLaven
  1 sibling, 1 reply; 4+ messages in thread
From: John Cosby @ 1996-12-06  0:00 UTC (permalink / raw)
  To: Brett M. Kettering


My $0.02.  It's all AFAIK, so take it as a voice of experience, not 
authority ;-)

Brett M. Kettering wrote:
> I have written Ada bindings to C in both Ada 83 and Ada 95.  The
> Interfaces.C package and pragma Convention of Ada 95 really make this a
> lot easier.  Lately I have been considering Ada 95 bindings to C++.
> 
> Can I get some input from persons that have written Ada 95 bindings to
> C++?  In my readings I have learned that the C++ class construct is
> analogous to the C struct.  So, this would imply that a binding to a
> class becomes an Ada 95 record that contains pointers to functions, as
> well as the Ada 95 versions of C data, as its elements?  What about
> class objects that are "thrown" as exceptions?

It's not that simple.  The representation of C++ objects is entirely
compiler-
dependent, as is the representation of Ada95 tagged types.  You cannot
imply
a mapping between different compilers (GNAT and g++ form an exception;
since
both use the same compiler engine, they use the same representation, and
can
swap objects to some degree).  In many programming environments, there
is no
way to (for example) make Ada95 invoke C++ object methods, or have C++
call
Ada95 dispatching functions.

> How does one go about using pragmas Import and Convention to bring these
> functions into an Ada 95 program to be called?

In the interfaces I've built I've tried several approaches (AIX,
PowerAda
and xlC++ environment).  I find I need to put 'extern "C"' around
statements
I want to call from Ada, and I generally have a thin C-interface layer
which
makes the C++ object method calls.  Coming back, C++ can invoke Ada95
access-to-
procedure calls (make sure you get the types right), but not for
dispatching
calls (calls resolved by a tagged type as the first parameter).

Then there's linking it all together, another challenge that's compiler 
dependent.  The OCS guys helped me come up with a way to link in the C++
so it would initialize its runtime prior to the Ada95 runtime
initialization,
but it took some work.  Otherwise, I'd get core dumps when I did
something 
like "cout" or "cin".  YMMV.

Also, the various Ada compiler companies have been discussing
standardizing
their methods for interfacing to C++.  I don't have any news other than
the
original announcement (check DejaNews), but it'd be nice to hear if
they've
made any progress (hint, hint, all you compiler vendors out there).

> Thanks for any leads.

I get to spend a month or so writing interfaces from an Ada95 API to
a C++ API starting Real Soon Now.  If I come up with any cool tricks,
I'll be sure to shout.

John
-- 
John Cosby                    SAIC Orlando               NOT speaking
for 
John.D.Cosby@cpmx.saic.com    (407) 282-6700 x216        SAIC




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

* Re: Ada bindings to C++
  1996-12-06  0:00 ` John Cosby
@ 1996-12-06  0:00   ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1996-12-06  0:00 UTC (permalink / raw)



John Cosby said

"It's not that simple.  The representation of C++ objects is entirely
compiler-
dependent, as is the representation of Ada95 tagged types.  You cannot
imply
a mapping between different compilers (GNAT and g++ form an exception;
since
both use the same compiler engine, they use the same representation, and
can
swap objects to some degree).  In many programming environments, there
is no
way to (for example) make Ada95 invoke C++ object methods, or have C++
call
Ada95 dispatching functions."


Please note that GNAT has an entirely procedural interface for defining
the format of dispatching tables, so by modifying the appropriate
runtime routine, it is possible to "make Ada 95 invoke C++ object methods",
for virtually any C++ compiler, not just g++ (interfacing to g++ is neither
harder or easier than interfacing to any other C++ compiler from GNAT).





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

* Re: Ada bindings to C++
  1996-12-04  0:00 Ada bindings to C++ Brett M. Kettering
  1996-12-06  0:00 ` John Cosby
@ 1996-12-07  0:00 ` Joel VanLaven
  1 sibling, 0 replies; 4+ messages in thread
From: Joel VanLaven @ 1996-12-07  0:00 UTC (permalink / raw)



  We here at OC Systems have been working on a general-purpose C++
bindings method that involves a sort of C-code "glue" layer.  We
have been working on this for our Ada95 upgrade to VisualAge.  I
would be happy to share our bindings methodology with you.  In order
to get everything to work using this method we recommend an automatic
bindings generator for reasons of amount of code and the importance of
of correctness.  Currently we do not have such a tool in a
general-purpose form.  However, I would be happy to give any one who
wants them pointers on how to do this.  If there is money involved, I
am sure that we could write a tool and/or bindings :).  Of course a
good standard interface to C++ supported by all compilers say through
the ARA ACE would be much better...

Brett M. Kettering (brettk@llnl.gov) wrote:
: I have written Ada bindings to C in both Ada 83 and Ada 95.  The
: Interfaces.C package and pragma Convention of Ada 95 really make this a
: lot easier.  Lately I have been considering Ada 95 bindings to C++.

: Can I get some input from persons that have written Ada 95 bindings to
: C++?  In my readings I have learned that the C++ class construct is
: analogous to the C struct.  So, this would imply that a binding to a
: class becomes an Ada 95 record that contains pointers to functions, as
: well as the Ada 95 versions of C data, as its elements?  What about
: class objects that are "thrown" as exceptions?

  Our bindings handle this, sort-of.  We catch C++ excpetions and convert
them into Ada exceptions but the C++ object that is thrown is lost.  All
that we can save on the Ada side is a string which I suppose would in
theory be able to contain an encryted version of the object, but we haven't
dealt with that yet.

: How does one go about using pragmas Import and Convention to bring these
: functions into an Ada 95 program to be called?

: Does the "c2ada" translator convert C++ header files to Ada 95 bindings?

  As long as they are the C subset of C++ :)

: Thanks for any leads.

: Brett
:  
: --------------------------------------------------
: Brett M. Kettering
: LLNL   P.O. Box 808 L-493   Livermore, CA.  94550
: E-mail: brettk@llnl.gov
: Voice : (510) 423-3467
: FAX   : (510) 422-1930
: --------------------------------------------------
-- 
-- Joel VanLaven




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

end of thread, other threads:[~1996-12-07  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-04  0:00 Ada bindings to C++ Brett M. Kettering
1996-12-06  0:00 ` John Cosby
1996-12-06  0:00   ` Robert Dewar
1996-12-07  0:00 ` Joel VanLaven

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