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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3020027a23cecd30,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!freenix!news.enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "John Arnsparger" Newsgroups: comp.lang.ada Subject: Problem passing In-Out parameter from C++ to Ada Date: Fri, 24 Jun 2005 13:02:47 -0500 Organization: Cuivre, Argent, Or Message-ID: Reply-To: johna42@houston.rr.com NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1119636207 55575 212.85.156.195 (24 Jun 2005 18:03:27 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 24 Jun 2005 18:03:27 +0000 (UTC) To: Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Importance: Normal X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:11625 Date: 2005-06-24T13:02:47-05:00 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 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