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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3020027a23cecd30 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!Spring.edu.tw!news.nctu.edu.tw!feeder.seed.net.tw!attdv1!attdv2!ip.att.net!newsfeed1.global.lmco.com!svlnews.lmms.lmco.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: Problem passing In-Out parameter from C++ to Ada Date: Fri, 24 Jun 2005 16:28:41 -0400 Organization: Earth Message-ID: References: NNTP-Posting-Host: 158.187.64.144 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Xref: g2news1.google.com comp.lang.ada:11629 Date: 2005-06-24T16:28:41-04:00 List-Id: "John Arnsparger" 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 > 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 > >