g++ -vs Java boolean

Mark Mitchell mark@codesourcery.com
Wed Aug 4 22:19:00 GMT 1999


>>>>> "Per" == Per Bothner <per@bothner.com> writes:

    Per> Not quite.  It's more that I see no use for being able to
    Per> overload them separately.

OK.  But, if we allow this then we need a way of doing overload
resolution.

    Per> No.  Obviously they are not the same type if they mangle
    Per> differently.

OK.

    >> Does `jshort' promote to `jint' or to `int'?

    Per> Any reason if can't be: Yes (to both).

Yup, but I was perhaps unclear.  I meant the "usual aritmetic
conversions", i.e., if you add a `jshort' and an `char' what do you
get?  You didn't answer my `true ? ((jint) 0) : ((int) 3)' question,
which is pretty much the same.

    >> Is `jboolean' like bool in that the only well-defined values
    >> are zero and one?  At present, it's like char, so `jboolean jb
    >> = 7' is presumably not the same as `jboolean jb = true.'  Is
    >> that the right thing?

    Per> jboolean should have the same TYPE_CODE as bool.

That's not *quite* an answer.  It's not the TYPE_CODE per se; it's the
values the underlying type can take on.  But, I think that making
`jboolean' have BOOLEAN_TYPE is probably sensible.

    Per> Perhaps the cleanest solution would be to consider the
    Per> relationship between jint and int like the relationship
    Per> between int and long (on a 32-bit system).  That suggests
    Per> that __java_int etc are new unique types, just like long.  I
    Per> believe wchar_t is treated the same way.

You still have to say what promotes to what.  By analogy with a 16-bit
wchar_t, `jshort' then promotes to `int', not to `jint'.  Which means
that, for example,

  void f(int);
  void f(jint);
  f ((jshort) 3);

calls `f(int)'.  That may or may not be what you'd like.  But, I think
this is a reasonably coherent semantics, by analogy with wchar_t. 

Note that this won't fix Tom's test-case, though.  He wrote something
like:

  void f(jboolean);
  void f(jint);
  f(true);

Considering `jboolean' like a bool-like wchar_t, `true' is not of a
matching type.  So, `f(jint)' will be called, which is probably *not*
the semantics you had in mind.  This is exactly like:
   
  void f(wchar_t);
  void f(int);
  f ((short) 3);

which calls `f(int)', even for a machine where sizeof(short) ==
sizeof(wchar_t).

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


More information about the Gcc-bugs mailing list