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,624801e212a1e237 X-Google-Attributes: gid103376,public From: John Cosby Subject: Re: Ada bindings to C++ Date: 1996/12/06 Message-ID: <32A84CF4.794B@cpmx.saic.com>#1/1 X-Deja-AN: 202717935 references: <32A606B9.5A66@llnl.gov> to: "Brett M. Kettering" content-type: text/plain; charset=us-ascii organization: SAIC Orlando mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (X11; I; OSF1 V3.2 alpha) Date: 1996-12-06T00:00:00+00:00 List-Id: 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