This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ -vs Java boolean
Tom Tromey <tromey@cygnus.com> writes:
> Mark> I'm not quite sure why the __java_* types are distinct types,
> Mark> rather than simply typedefs.
> I've CC'd Per Bothner, who probably does know all the issues.
Well, I did, but it has been a while ...
One issue (as Tom says) is name mangling. It is desirable that
(say) the Java "long" type mangle the same on all platforms.
It is *required* that Java "long" have the same size (64 bits)
on all platforms. Thus we cannot just typedef the Java type
to some C++ type. We could use a __mode__ attribute, but I
recall having problems getting them to mangle as desired. The
builtin __java_long etc types seemed the cleanest solution of
the various ones we tried.
Another advantage of special builtin types is error checking.
It would be an error in C++ code to use "int" or "long" as the
parameter or result type of a method of a Java class; you should
use "jint" or "jlong" instead. Having special Java types
allows us to catch this error.
> I don't understand why we need __java_boolean at all.
> We could just "typdef bool jboolean" and be done, it seems like.
> The other types are more subtle, I think.
Remember that the C++ bool type is *not* 1 byte on most architectures.
(I believe this is one of things we are changing for the "new ABI".)
Mark earlier wrote:
> The `__java_boolean' type is an INTEGER_TYPE with 8
> bits; it's essentially `char' with a different name. That's not the
> same type as `false', which has type `bool'.
There is code in record_builtin_java_type to (essentially)
TREE_SET_CODE (java_boolean_code, BOOLEAN_TYPE), but it looks like I
commented it out, presumably because for some reason it didn't work.
Perhaps it should now be un-commented?
--
--Per Bothner
bothner@pacbell.net per@bothner.com http://home.pacbell.net/bothner/