comp.lang.ada
 help / color / mirror / Atom feed
From: "John Arnsparger" <johna42@houston.rr.com>
To: <comp.lang.ada@ada-france.org>
Subject: Problem passing In-Out parameter from C++ to Ada
Date: Fri, 24 Jun 2005 13:02:47 -0500
Date: 2005-06-24T13:02:47-05:00	[thread overview]
Message-ID: <mailman.93.1119636206.17633.comp.lang.ada@ada-france.org> (raw)

Hi all,

I'm looking for some help with interfacing Ada with C++.  The GNAT
User's Guide includes "A Simple Example", which I have built and it
works except for the part in which Ada_Method2 uses the "this" class
pointer, passed as an in out parameter,  to write a value back to C++
class data member.  That program runs, but never sets the value of the
data member "a_value" to 3030 as it should.

I tried an even simpler example (see below) in which all I do is pass an
integer from C++ to Ada as an in out parameter, and I get segmentation
fault/core dump.

I have seen identical behavior on two gcc/gnat installations: one is a
Redhat Linux PC version 3.2.3 on a 64-bit Xeon PC and the other is using
Cygwin gcc 3.4.4 installed yesterday on my Pentium PC via Cygwin.com.
Does anyone know if this should work, or if it does in some other
environment? Or is there another approach that is required?
Any other info or advice would be greatly appreciated.

Regards,

John Arnsparger


Here is the code I'm using:

//cpp_main.C
#include <stdio.h>
extern "C" {
   void adainit (void);
   void adafinal (void);
   void var_test (int v);
}
int main ()
{
   adainit ();
   int v1 = 3030;
   printf ("In cpp_main, v1 = %d \n", v1);
   var_test (v1);
   printf ("In cpp_main, after var_test call, v1 = %d \n", v1);
   adafinal ();
}

-- simple_cpp_interface.ads
package Simple_Cpp_Interface is
   procedure Var_Test (V : in out Integer);
   pragma Export (C, Var_Test, "var_test");
end Simple_Cpp_Interface;

-- simple_cpp_interface.adb
with TEXT_IO;
use  TEXT_IO;
package body Simple_Cpp_Interface is

   package IO is new TEXT_IO.INTEGER_IO(Integer);

   procedure Var_Test (V : in out Integer) is
   V1 : Integer := V;
   begin
      Put ("In Var_Test, V1= "); IO.Put ( V1 ); New_Line;
   end Var_Test;

end Simple_Cpp_Interface;

-- Building it with the following commands:

g++ -c cpp_main.C
g++ -c simple_cpp_interface.adb
gnatbind -n simple_cpp_interface
gnatlink simple_cpp_interface -o cpp_main --LINK=g++ -lstdc++ cpp_main.o
cpp_main
In cpp_main, v1 = 3030
Segmentation fault





             reply	other threads:[~2005-06-24 18:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-24 18:02 John Arnsparger [this message]
2005-06-24 20:28 ` Problem passing In-Out parameter from C++ to Ada REH
2005-06-25  6:03 ` Jeffrey Carter
replies disabled

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