From: "REH" <bogus@nowhere.net>
Subject: Re: Problem passing In-Out parameter from C++ to Ada
Date: Fri, 24 Jun 2005 16:28:41 -0400
Date: 2005-06-24T16:28:41-04:00 [thread overview]
Message-ID: <d9hqdp$641@cui1.lmms.lmco.com> (raw)
In-Reply-To: mailman.93.1119636206.17633.comp.lang.ada@ada-france.org
"John Arnsparger" <johna42@houston.rr.com> wrote in message
news:mailman.93.1119636206.17633.comp.lang.ada@ada-france.org...
> 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);
try changing the above to:
void var_test(int* v);
> }
> int main ()
> {
> adainit ();
> int v1 = 3030;
> printf ("In cpp_main, v1 = %d \n", v1);
> var_test (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
>
>
next prev parent reply other threads:[~2005-06-24 20:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-24 18:02 Problem passing In-Out parameter from C++ to Ada John Arnsparger
2005-06-24 20:28 ` REH [this message]
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