comp.lang.ada
 help / color / mirror / Atom feed
* Re: Can Ada95 interface with C++?
       [not found]           ` <tx1bu9rp8sr.fsf@cygnus.com>
@ 1997-02-11  0:00             ` Larry Kilgallen
  1997-02-12  0:00               ` Joel VanLaven
  1997-02-12  0:00             ` Robert Dewar
  1997-02-20  0:00             ` Samuel Mize
  2 siblings, 1 reply; 9+ messages in thread
From: Larry Kilgallen @ 1997-02-11  0:00 UTC (permalink / raw)



In article <tx1bu9rp8sr.fsf@cygnus.com>, Ken Raeburn <raeburn@cygnus.com> writes:
> 
> People have been saying "yes you can do it", but I'm wondering how
> it's done, since Annex B only talks about C, COBOL, and Fortran.
> 
> Does it require programmers in both languages to use C-compatible
> interfaces for anything to be shared?  Or can Ada interface with
> "real" C++ code?

Ada implementors realize there is demand for C++ interoperation,
and are likely to attempt some sort of compatibility.

Neither implementors nor the Ada standard, however, can stipulate
C++ compatibility because there is not yet an international standard
for the C++ language.  Even for a particular existing C++ product,
it would not be wise for an Ada vendor to make sweeping compatibility
claims because that C++ vendor is likely to go off and change their
implementation whenever a C++ standard arrives.

> with virtual functions be described to an Ada compiler?  (I think
> telling the Ada compiler *which* C++ implementation is being used, on
> platforms supporting multiple incompatible ones, might be a reasonable
> concession; just no low-level details.)

I can vote for that approach as well, since I also do not have to
implement a compiler :-)

> I've only just started learning about Ada, so I don't know how well
> the C++ constructs correspond to the Ada features I have yet to learn.

www.adahome.com points to at least one document comparing the two
languages which seems to give a valuable description of Ada in
terms which should be familiar to C++ programmers.

Larry Kilgallen




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

* Re: Can Ada95 interface with C++?
  1997-02-11  0:00             ` Can Ada95 interface with C++? Larry Kilgallen
@ 1997-02-12  0:00               ` Joel VanLaven
  1997-02-14  0:00                 ` Ken Raeburn
                                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Joel VanLaven @ 1997-02-12  0:00 UTC (permalink / raw)



Larry Kilgallen (kilgallen@eisner.decus.org) wrote:
: In article <tx1bu9rp8sr.fsf@cygnus.com>, Ken Raeburn <raeburn@cygnus.com> writes:
: > 
: > People have been saying "yes you can do it", but I'm wondering how
: > it's done, since Annex B only talks about C, COBOL, and Fortran.
: > 
: > Does it require programmers in both languages to use C-compatible
: > interfaces for anything to be shared?  Or can Ada interface with
: > "real" C++ code?

: Ada implementors realize there is demand for C++ interoperation,
: and are likely to attempt some sort of compatibility.

: Neither implementors nor the Ada standard, however, can stipulate
: C++ compatibility because there is not yet an international standard
: for the C++ language.  Even for a particular existing C++ product,
: it would not be wise for an Ada vendor to make sweeping compatibility
: claims because that C++ vendor is likely to go off and change their
: implementation whenever a C++ standard arrives.

Currently as I understand it almost no Ada compilers can interface to
"real" C++ methods/types/etc. except for GNAT interfacing to GNU C++.
Plans are in the works for more of the GNAT style interfaces for other
compilers (like ours, though don't hold your breath).  There are some
technical difficulties involved and the Ada community is attempting to
standardize the interface for portability, economic, and stylistic
reasons.

  Until then if you REALLY need to connect to some C++ code that
was not written with interopability in mind you could try something akin
to what we are doing for VisualAge.  I feel strange explaining it a bunch
of times but what the heck.  Basically you can write bindings that use
C as the glue between Ada95 and C++ that will allow all sorts of OO
things like dispatching from one language to the other (not as efficiently
but hey, it does dispatch!) and even passing exceptions across the language
boundry.  This type of binding is writer-wise much more difficult than
built in support would be and requires either an automatic generation
tool (sorry none available that I know of :) or a lot of work.

: > with virtual functions be described to an Ada compiler?  (I think
: > telling the Ada compiler *which* C++ implementation is being used, on
: > platforms supporting multiple incompatible ones, might be a reasonable
: > concession; just no low-level details.)

: I can vote for that approach as well, since I also do not have to
: implement a compiler :-)

I vote for that approach too, even though I used another extensively :)

: > I've only just started learning about Ada, so I don't know how well
: > the C++ constructs correspond to the Ada features I have yet to learn.

: www.adahome.com points to at least one document comparing the two
: languages which seems to give a valuable description of Ada in
: terms which should be familiar to C++ programmers.

On the surface some things that seem simple turn out not to be.  For many
things the C++ way of doing things is just different than the Ada95 way.
For example, C++ classes without virtual functions are called
"nonpolymorphic" classes.  There is no such thing in Ada95 because a
a CALL to a primitive op of a tagged type in Ada95 is what determines
whether the call dispatches, not the declaration of the operation.  Another
big problem is the different way initialization/finalization is handled.
None of this even touches upon MI (ack) and templates/generics (generics
get instantiated while templates just sort of instantiate themsleves on
the fly or something.  (I don't claim to be a C++ expert :).

  Not to say that taken a C++ program one can't "do the same (or similar)
thing" in Ada95.  It is just that sometimes one can do the same things
but they must be done in a different (read maybe incompatible) way.
-- 
-- Joel VanLaven




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

* Re: Can Ada95 interface with C++?
       [not found]           ` <tx1bu9rp8sr.fsf@cygnus.com>
  1997-02-11  0:00             ` Can Ada95 interface with C++? Larry Kilgallen
@ 1997-02-12  0:00             ` Robert Dewar
  1997-02-20  0:00             ` Samuel Mize
  2 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 1997-02-12  0:00 UTC (permalink / raw)



Ken asked

<<I've only just started learning about Ada, so I don't know how well
the C++ constructs correspond to the Ada features I have yet to learn.
But is it possible (or feasible) to make compatible those constructs
that might directly correlate between the languages?>>

GNAT provides for direct interface between Ada 95 and C++ (for example, it
can use exactly the same data structures for tagged types that C++ uses
for classes). The SGI implementation of GNAT is for example interoperable
with SGI Delta C++.





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

* Re: Can Ada95 interface with C++?
  1997-02-12  0:00               ` Joel VanLaven
@ 1997-02-14  0:00                 ` Ken Raeburn
  1997-02-24  0:00                 ` Robert Dewar
  1997-02-24  0:00                 ` Robert Dewar
  2 siblings, 0 replies; 9+ messages in thread
From: Ken Raeburn @ 1997-02-14  0:00 UTC (permalink / raw)



Thanks for the info, everyone.

Although I'd only be using GNAT and G++ in the forseeable future
(unless there's a better free implementation with sources for a
variety of UNIX systems :), it sounds like for portability reasons I
should wait and see, and stick with C for the glue code in the
meantime.

And thanks for the pointer to the C++/Ada stuff on adahome.  I'll look
it up, since I'm much more familiar with C++ (er, well, with what C++
was before ANSI started working on it).

Ken




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

* Re: Can Ada95 interface with C++?
       [not found]     ` <dewar.855234605@merv>
@ 1997-02-18  0:00       ` John Cosby
  0 siblings, 0 replies; 9+ messages in thread
From: John Cosby @ 1997-02-18  0:00 UTC (permalink / raw)



Robert Dewar wrote:
> 
> Ara says
> 
> "2)  Exceptions cannot propagate across language boundarie"
> 
> In general your comments are confused between implementation and language
> requirements. If your statement referred to some particular compiler
> this might be correct, but as a general statement about Ada 95 and
> C++ interfacing it is wrong.

Perhaps it should be rephrased as "Exceptions usually do not propogate
across language boundaries."  Is there a pair of compilers out there
that
allow exception propogation between Ada95 and C++?  Such has not been my
experience, and I've been looking.

> There is absolutely no reason why exceptions should not propagate across
> language boundiares. GNAT does not currently imlplement this in any
> automatic manner, but certainly it is our plan to do so as part of
> installing the new genral exception scheme.

Well, if even GNAT doesn't do it with gcc/g++, how can one expect
compiler
vendors operating from different code bases to do this?  Even the
definition
of exceptions is being debated in another thread in this group.  How can
we
expect different corporations to come up with an interoperable set of 
exception propogation rules when there's not even a standard way of
making
Ada95 and C++ interface?  Once you decide how to do it for standard
exceptions (Is there a standard set of C++ exceptions?  My reference
doesn't
have any - just base types and the ubiquitous (...)), how will you 
propogate user-defined exceptions?  It's not a small challenge.

Not that I'd mind having the capability, mind you... I'm getting tired
of debugging "glue" code core dumps that happened when my Ada runtime
couldn't
handle the C++ exception in the routines the Ada calls.

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




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

* Re: Can Ada95 interface with C++?
       [not found]           ` <tx1bu9rp8sr.fsf@cygnus.com>
  1997-02-11  0:00             ` Can Ada95 interface with C++? Larry Kilgallen
  1997-02-12  0:00             ` Robert Dewar
@ 1997-02-20  0:00             ` Samuel Mize
  1997-02-21  0:00               ` Robert Dewar
  2 siblings, 1 reply; 9+ messages in thread
From: Samuel Mize @ 1997-02-20  0:00 UTC (permalink / raw)



In article <tx1bu9rp8sr.fsf@cygnus.com>,
Ken Raeburn  <raeburn@cygnus.com> wrote:
>People have been saying "yes you can do it", but I'm wondering how
>it's done, since Annex B only talks about C, COBOL, and Fortran.
>...Or can Ada interface with
>"real" C++ code? ...
>But is it possible (or feasible) to make compatible those constructs
>that might directly correlate between the languages?

It is apparently both possible and feasible, since (I understand)
GNAT does it.  However, as you noted, it is not in Annex B, so it
is not a standard item.  It is vendor-dependent.

(There wasn't an ISO standard for C++ when Ada95 was standardized.
It would have been problematic to define a standard interface to an
unstandardized language.)

Samuel Mize







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

* Re: Can Ada95 interface with C++?
  1997-02-20  0:00             ` Samuel Mize
@ 1997-02-21  0:00               ` Robert Dewar
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 1997-02-21  0:00 UTC (permalink / raw)



<<(There wasn't an ISO standard for C++ when Ada95 was standardized.
It would have been problematic to define a standard interface to an
unstandardized language.)

Samuel Mize>>


No need to use the past tense, there STILL is no ISO standard for C++





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

* Re: Can Ada95 interface with C++?
  1997-02-12  0:00               ` Joel VanLaven
  1997-02-14  0:00                 ` Ken Raeburn
  1997-02-24  0:00                 ` Robert Dewar
@ 1997-02-24  0:00                 ` Robert Dewar
  2 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 1997-02-24  0:00 UTC (permalink / raw)



Joel says

<<Currently as I understand it almost no Ada compilers can interface to
"real" C++ methods/types/etc. except for GNAT interfacing to GNU C++.
Plans are in the works for more of the GNAT style interfaces for other
compilers (like ours, though don't hold your breath).>>


No, this is wrong, there is nothing GNU C++ specific about the GNAT
C++ interface, and indeed the most extensive use of this interface is
in conjunction with the SGI Delta C++ compiler, which is not compatible
with G++.

In GNAT, a single runtime unit defines the layout of tagged types and
the dispatching interface, and to interface to a new C++ compiler, only
this one runtime unit must be modified (zero changes are required to the
compiler itself, it is not even necessary to recompile the compiler).






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

* Re: Can Ada95 interface with C++?
  1997-02-12  0:00               ` Joel VanLaven
  1997-02-14  0:00                 ` Ken Raeburn
@ 1997-02-24  0:00                 ` Robert Dewar
  1997-02-24  0:00                 ` Robert Dewar
  2 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 1997-02-24  0:00 UTC (permalink / raw)



Joel says

<<For example, C++ classes without virtual functions are called
"nonpolymorphic" classes.  There is no such thing in Ada95 because a
a CALL to a primitive op of a tagged type in Ada95 is what determines
whether the call dispatches, not the declaration of the operation.  Another
big problem is the different way initialization/finalization is handled.
None of this even touches upon MI (ack)>>


There is no problem in defining the equivalent of nonpolymorphic classes.
To define "methods" in Ada 95 that are not virtual (using the C++
terminology), just don't make them primitive. Then they can be applied
to any member of the class (the formal type is x'class in this case).

It *is* the declaration of the operation in Ada 95 that determines whether
the call dispatches. A class wide operation never dispatches. So the first
concern here just seems plain wrong.

I do not see why initialization/finalization is a big problem either. The
GNAT interface design provides a clean way of interfacing to constructors
and destructors (though this is not fuly implemented yet).

Finally, the GNAT design handles multiply inherited classes without a
problem. You cannot *define* such a class within Ada, but you can
certainly *import* such a class.





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

end of thread, other threads:[~1997-02-24  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5csvbd$ia2@top.mitre.org>
     [not found] ` <32F60684.59E2@gslink.net>
     [not found]   ` <32F94DD7.3F54BC7E@worldnet.att.net>
     [not found]     ` <1997Feb6.150722.14570@ocsystems.com>
     [not found]       ` <1997Feb6.130819.1@eisner>
     [not found]         ` <dewar.855276105@merv>
     [not found]           ` <tx1bu9rp8sr.fsf@cygnus.com>
1997-02-11  0:00             ` Can Ada95 interface with C++? Larry Kilgallen
1997-02-12  0:00               ` Joel VanLaven
1997-02-14  0:00                 ` Ken Raeburn
1997-02-24  0:00                 ` Robert Dewar
1997-02-24  0:00                 ` Robert Dewar
1997-02-12  0:00             ` Robert Dewar
1997-02-20  0:00             ` Samuel Mize
1997-02-21  0:00               ` Robert Dewar
     [not found]     ` <dewar.855234605@merv>
1997-02-18  0:00       ` John Cosby

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