Object.h -vs- nacd_1

Tom Tromey tromey@redhat.com
Tue Jun 19 17:04:00 GMT 2001


Consider this Java program and its associated native code:

    public class X1
    {
      void nacd_1 ()
      {
	System.out.println ("hi");
      }

      void foo ()
      {
	nacd_1 ();
      }

      public native void z ();

      public static void main (String[] args)
      {
	X1 x = new X1 ();
	x.foo ();
	x.z ();
      }
    }

    #include "X1.h"

    void X1::z ()
    {
      nacd_1 ();
    }

If you compile this and run it, it will abort on the call to x.z().
That's because Object.h uses the names nacd_1() and nacd_2() to
reserve slots in the vtable.  However these slots don't actually
correspond to virtual functions.

You can also arrange for an error from the C++ compiler if you change
nacd_1()'s return type (say, to `int').

How can we fix this?

Ideally we would find a way to do this without requiring a change to
g++.  The g++ maintainers seem increasingly reluctant to do this.

One approach would be to simply choose a really obscure name, like
`$$$$$$$'.  I dislike this sort of hack though.  (nacd_1() itself is
unlikely to occur.  Perhaps this problem is simply ignorable.  That is
gross though.)

Tom



More information about the Java mailing list