From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d1ced5efd53fe6a1 X-Google-Attributes: gid103376,public From: jvl@ocsystems.com (Joel VanLaven) Subject: Re: Can Ada95 interface with C++? Date: 1997/02/12 Message-ID: <1997Feb12.004642.31821@ocsystems.com>#1/1 X-Deja-AN: 218152692 references: <5csvbd$ia2@top.mitre.org> <32F60684.59E2@gslink.net> <32F94DD7.3F54BC7E@worldnet.att.net> <1997Feb6.150722.14570@ocsystems.com> <1997Feb6.130819.1@eisner> <1997Feb11.153355.1@eisner> organization: OC Systems, Inc. newsgroups: comp.lang.ada Date: 1997-02-12T00:00:00+00:00 List-Id: Larry Kilgallen (kilgallen@eisner.decus.org) wrote: : In article , Ken Raeburn 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