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: 109fba,c7946f5c82eedec X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,c7946f5c82eedec X-Google-Attributes: gid103376,public From: ka@socrates.hr.att.com (Kenneth Almquist) Subject: Ada/C++ linkange on SGI. Date: 1996/10/09 Message-ID: <53golu$a37@nntpa.cb.lucent.com>#1/1 X-Deja-AN: 188295158 references: <325A9700.384A@ti.com> organization: Lucent Technologies, Columbus, Ohio newsgroups: comp.lang.c++,comp.lang.ada Date: 1996-10-09T00:00:00+00:00 List-Id: > C++ compiler : MIPSpro C++ 6.2 > Ada compiler : Verdix VADS 6.2 I assume that's an Ada 83 compiler. > If, for example, I had two instances of the class I want to be able > to call INSTANCE1.class_function() and INSTANCE2.class_function() from > Ada. Does anyone have any insight about how I might do this? Well, first you want to write an Ada definition which corresponds to the C++ class. If you have it, you should read the compiler documen- tation to determine how each compiler does layout. Otherwise, you can probably figure it out by trial and error. Typically, you will end up with something like: class cc { type cc is record int a; a : integer; int b; b : integer; void operate(); end record; }; If the C++ class contains any virtual members, the C++ compiler will add a tag field which identifies the type, so your Ada declaration might look like: type cc is record tag : system.address; a : integer; b : integer; end record; Then if you create any class instances using Ada, you have to initialize the tag field by copying it from a class instance created using C++. Calling a non-virtual member function from Ada is no different from calling any other C++ function from Ada, except that in the C++ code one argument will precede the function name. C++: a.operate(); Ada: operate(a); Virtual functions in C++ support run time dispatching, which is not available in Ada 83. (It is in Ada 95.) If you know the type at compile time, virtual functions require no special handling. Otherwise, your best bet in Ada 83 is to write wrapper function in C++ which calls the virtual function. For example: void operate(class cc *a) { a->operate(); } The above approaches should work with most compilers, but again, if you have access to documentation describing your compilers, your best bet is to work from that. Kenneth Almquist