public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
@ 2004-10-20 16:53 karl at grebyn dot com
  2004-10-22 12:21 ` [Bug ada/18085] " karl at grebyn dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: karl at grebyn dot com @ 2004-10-20 16:53 UTC (permalink / raw)
  To: gcc-bugs

This program source is modified (additional print statements) from:
       
http://gcc.gnu.org/onlinedocs/gcc-3.4.2/gnat_ugn_unw/A-Simple-Example.html#A-Simple-Example

An example of interoperating C++ and Ada code.  The results seem to
indicate that the calls between the two languages are working OK, but
that the parameter passing isn't.  I guess that indicates something in the ABI,
perhaps?

The final value in A::method2 should be 3030, and the intermediate
values in the Ada calls are wrong.

$ gcc -v
Reading specs from /opt/lib/gcc/i686-pc-linux-gnu/3.4.2/specs
Configured with: ./configure --prefix=/opt --enable-languages=ada,c,c++
Thread model: posix
gcc version 3.4.2
$ uname -a
Linux ezekiel 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
$ cat /etc/issue
Red Hat Linux release 9 (Shrike)
Kernel \r on an \m

$./cpp_main
in A::A, a_value = 1010
=== in A::method2, a_value was = 1010
in Ada_Method2, O_Value = 134582632
in Ada_Method2, A_Value =-1073749612
in A::method1, a_value = 2020
in Ada_Method2, O_Value = 134582632
in Ada_Method2, A_Value =-1073749612
in Ada_Method2, O_Value = 134582632
in Ada_Method2, A_Value = 3030
=== in A::method2, a_value = 2020
$ cat compile
#! /bin/csh
# compilation script to evidence the bug
gnatmake -c simple_cpp_interface
c++ -c cpp_main.C
c++ -c ex7.C
gnatbind -n simple_cpp_interface
gnatlink simple_cpp_interface -o cpp_main --LINK=c++  -lstdc++ ex7.o cpp_main.o
$ cat *.C *.h *.ad?
// cpp_main.C start

#include "ex7.h"
#include <stdio.h>

extern "C" {
  void adainit (void);
  void adafinal (void);
  void method1 (A *t);
}

void method1 (A *t)
{
t->method1 ();
}

int main ()
{
  A obj;
  adainit ();
  obj.method2 (3030);
  adafinal ();
}

// cpp_main.C end
//ex7.C start

#include "ex7.h"
#include <stdio.h>

extern "C" { void ada_method2 (A *t, int v);}

void A::method1 (void)
{
  a_value = 2020;
  printf ("in A::method1, a_value = %d \n",a_value);

}

void A::method2 (int v)
{
  printf ("=== in A::method2, a_value was = %d \n",a_value);
  ada_method2 (this, v);
  printf ("=== in A::method2, a_value = %d \n",a_value);

}

A::A(void)
{
  a_value = 1010;
  printf ("in A::A, a_value = %d \n",a_value);
}

//ex7.C end
// ex7.h start

class Origin {
 public:
  int o_value;
};

class A : public Origin {
 public:
  void method1 (void);
  virtual void method2 (int v);
  A();
  int a_value;
};

// ex7.h end
-- simple_cpp_interface.adb start
with Ada.Text_Io; use Ada.Text_Io;
package body Simple_Cpp_Interface is

procedure Ada_Method2 (This : in out A; V : Integer) is
   begin
      Ada.Text_Io.Put_Line ("in Ada_Method2, O_Value =" & Integer'Image
(This.O_Value));
      Ada.Text_Io.Put_Line ("in Ada_Method2, A_Value =" & Integer'Image
(This.A_Value));
      Method1 (This);
      Ada.Text_Io.Put_Line ("in Ada_Method2, O_Value =" & Integer'Image
(This.O_Value));
      Ada.Text_Io.Put_Line ("in Ada_Method2, A_Value =" & Integer'Image
(This.A_Value));
      This.A_Value := V;
      Ada.Text_Io.Put_Line ("in Ada_Method2, O_Value =" & Integer'Image
(This.O_Value));
      Ada.Text_Io.Put_Line ("in Ada_Method2, A_Value =" & Integer'Image
(This.A_Value));
   end Ada_Method2;

end Simple_Cpp_Interface;

-- simple_cpp_interface.adb end
-- simple_cpp_interface.ads start

package Simple_Cpp_Interface is
   type A is limited
      record
         O_Value : Integer;
         A_Value : Integer;
      end record;

pragma Convention (CPP, A);

procedure Method1 (This : in out A);
pragma Import (C, Method1);

procedure Ada_Method2 (This : in out A; V : Integer);
pragma Export (C, Ada_Method2);

end Simple_Cpp_Interface;

-- simple_cpp_interface.ads end

-- 
           Summary: [Ada] - C++ interoperability sample program fails,
                    3.4.2, Linux 2.4.20-8, Red Hat 9.0
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: karl at grebyn dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
@ 2004-10-22 12:21 ` karl at grebyn dot com
  2004-10-24 22:39 ` karl at grebyn dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: karl at grebyn dot com @ 2004-10-22 12:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From karl at grebyn dot com  2004-10-22 12:21 -------
Confirmed still present in current snapshot for gcc 4.0

Reading specs from /home/karl/gnat/lib/gcc/i686-pc-linux-gnu/4.0.0/specs
Configured with: ../gcc/gcc-4.0-20041017/./configure --prefix=/home/karl/gnat
--enable-languages=c,c++,ada
Thread model: posix
gcc version 4.0.0 20041017 (experimental)


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|3.4.2                       |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
  2004-10-22 12:21 ` [Bug ada/18085] " karl at grebyn dot com
@ 2004-10-24 22:39 ` karl at grebyn dot com
  2004-10-29 13:28 ` charlet at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: karl at grebyn dot com @ 2004-10-24 22:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From karl at grebyn dot com  2004-10-24 22:39 -------
Problem is that the documentation has an incorrect specification of the interface.

By changing ex7.h to the following, the program works.
     
     //ex7.h
     
     class Origin {
      public:
       int a_value;
     };
     class A : public Origin {
      public:
       void method1 (void);
       virtual void method2 (int v);
       A();
       //       int   a_value;
     };

I leave it to the language lawyers to determine why some sort of error wasn't
raised before...

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
  2004-10-22 12:21 ` [Bug ada/18085] " karl at grebyn dot com
  2004-10-24 22:39 ` karl at grebyn dot com
@ 2004-10-29 13:28 ` charlet at gcc dot gnu dot org
  2004-11-25 13:39 ` charlet at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: charlet at gcc dot gnu dot org @ 2004-10-29 13:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From charlet at gcc dot gnu dot org  2004-10-29 13:28 -------
I believe recent changes in Interfaces.CPP may have fixed things, if
there's indeed something to fix.

Could you verify ?

Arno

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
                   ` (2 preceding siblings ...)
  2004-10-29 13:28 ` charlet at gcc dot gnu dot org
@ 2004-11-25 13:39 ` charlet at gcc dot gnu dot org
  2004-11-25 14:29 ` karl at grebyn dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: charlet at gcc dot gnu dot org @ 2004-11-25 13:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From charlet at gcc dot gnu dot org  2004-11-25 13:38 -------
No feedback received, although it's pretty clear that this is working
"as expected" on mainline, so closing.

Arno

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
                   ` (3 preceding siblings ...)
  2004-11-25 13:39 ` charlet at gcc dot gnu dot org
@ 2004-11-25 14:29 ` karl at grebyn dot com
  2004-11-25 14:51 ` charlet at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: karl at grebyn dot com @ 2004-11-25 14:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From karl at grebyn dot com  2004-11-25 14:28 -------
Subject: Re:  [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0

I thought I updated that it appears to be a documentation issue...

-- Karl --


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
                   ` (4 preceding siblings ...)
  2004-11-25 14:29 ` karl at grebyn dot com
@ 2004-11-25 14:51 ` charlet at gcc dot gnu dot org
  2004-11-25 14:59 ` karl at grebyn dot com
  2004-11-25 15:10 ` karl at grebyn dot com
  7 siblings, 0 replies; 9+ messages in thread
From: charlet at gcc dot gnu dot org @ 2004-11-25 14:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From charlet at gcc dot gnu dot org  2004-11-25 14:51 -------
<<I thought I updated that it appears to be a documentation issue...>>

Not the one you raised: you seemed to have confused o_value and
a_value, which are two different names and variables.

Now, I thought that recent changes to Interfaces.CPP may have
fixed this issue, although I am no longer sure this is the case,
so it would be interesting to have a confirmation, and re-open this
PR if there's still an issue.

Of course, it might still be the case that the example in the documentation
is wrong, but in this case, the error would be on the Ada code, not on the
C++ code as far as I can see.

Arno

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
                   ` (5 preceding siblings ...)
  2004-11-25 14:51 ` charlet at gcc dot gnu dot org
@ 2004-11-25 14:59 ` karl at grebyn dot com
  2004-11-25 15:10 ` karl at grebyn dot com
  7 siblings, 0 replies; 9+ messages in thread
From: karl at grebyn dot com @ 2004-11-25 14:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From karl at grebyn dot com  2004-11-25 14:59 -------
Subject: Re:  [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0

I will download the latest 4.0 snapshot and take another look.

-- Karl --


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug ada/18085] [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0
  2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
                   ` (6 preceding siblings ...)
  2004-11-25 14:59 ` karl at grebyn dot com
@ 2004-11-25 15:10 ` karl at grebyn dot com
  7 siblings, 0 replies; 9+ messages in thread
From: karl at grebyn dot com @ 2004-11-25 15:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From karl at grebyn dot com  2004-11-25 15:10 -------
Subject: Re:  [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0

The latest 4.0 snapshot won't build thanks to a breakage in the Ada.  But
the example in the documentation works correctly now.  Maybe I goofed up the
o_ and the a_ by manually copying.  I saved straight from the html page and
it did indeed work (with gcc 3.4.3).

-- Karl --


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18085


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-11-25 15:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 16:53 [Bug ada/18085] New: [Ada] - C++ interoperability sample program fails, 3.4.2, Linux 2.4.20-8, Red Hat 9.0 karl at grebyn dot com
2004-10-22 12:21 ` [Bug ada/18085] " karl at grebyn dot com
2004-10-24 22:39 ` karl at grebyn dot com
2004-10-29 13:28 ` charlet at gcc dot gnu dot org
2004-11-25 13:39 ` charlet at gcc dot gnu dot org
2004-11-25 14:29 ` karl at grebyn dot com
2004-11-25 14:51 ` charlet at gcc dot gnu dot org
2004-11-25 14:59 ` karl at grebyn dot com
2004-11-25 15:10 ` karl at grebyn dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).