This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: GCJ and C++ (calling Java from C++)
- From: Lothar Werzinger <lothar at tradescape dot biz>
- To: java at gcc dot gnu dot org
- Date: Wed, 30 Nov 2005 17:16:42 -0800
- Subject: Re: GCJ and C++ (calling Java from C++)
- References: <200511281612.37450.lothar@tradescape.biz> <200511301558.02459.lothar@tradescape.biz> <438E488E.1020008@redhat.com>
On Wednesday 30 November 2005 16:49, Bryce McKinlay wrote:
> Lothar Werzinger wrote:
> >in the generated headers from gcjh i get this:
> >
> > class org::eclipse::emf::examples::extlibrary::Addressable
> >
> > : public ::java::lang::Object
> >
> > {
> > ...
> >
> > class org::eclipse::emf::examples::extlibrary::Library
> >
> > : public ::java::lang::Object
> >
> > {
> > ...
> >
> > class org::eclipse::emf::examples::extlibrary::impl::LibraryImpl
> >
> > : public ::org::eclipse::emf::ecore::impl::EObjectImpl
> >
> > {
> > ...
>
> C++ doesn't directly support the idea of a Java interface - we'd need to
> make some enhancements to the C++ front end in order to support this.
>
> As a workaround, you can cast your object reference to the interface
> type (using a C++ static_cast, for example), and then call the interface
> method on that. Just be careful that the object you are casting really
> does implement the interface!
I'm not sure what you suggest here. If you look at the C++ code I use you'll
notice that I call a static Method that returns a Java Object of type
Library. What goes wrong is if I call any method on the returned object.
As I already get a Library object I don't know what a cast would do different.
> bug 15411 is a different issue, as in that case it can actually generate
> a broken virtual call because C++'s idea of the vtable layout will be
> different from reality. 15411 shouldn't effect you in this case because
> there is no abstract class here.
> Bryce
Well it is similar in the sense that if gcjh does not generate the inheritance
relationship I suppose it also generates a wrong vtable, as inheritance
(inheriting virtual methods from interfaces) does affect the vtable - right?
I wonder if we couldn't write a Java program that uses Java reflection to
generate the (correct) C++ headers. I guess it would probably much easier to
do that in Java than in C and we could use gcj to generate the gcjh
executable from the Java code.
Lothar
--
Lothar Werzinger Dipl.-Ing. Univ.
framework & platform architect
Tradescape Inc.
111 West St. John Street, Suite 200
San Jose, Ca 95113
email: lothar@tradescape.biz