From: | moresys@world.std.com (More Systems Employee) |
Newsgroups: | comp.lang.java,comp.lang.c++,comp.compilers |
Date: | 19 May 1996 18:25:34 -0400 |
Organization: | MORE Systems, inc. |
References: | 96-05-036 |
Keywords: | Java, C++ |
Drinie@xs4all.nl says...
>I know that Java does not support pointer arithmetic.
>
>But as the Java virtual machine gets integrated in many OSes it would
>be nice to use it as a target language for other languages.
>
>Is it possible (and will Sun allow it) to extend the JVM to support
>pointer arithmetic.
No. This would be extremely unpopular, as it would completely invalidate
Java's much-touted security.
However, it would be possible to emulate a C environment using a simple
byte array. A C pointer would translate into an array offset, and
all the pointer arithmetic and arbitrary casts of types could be
supported. With a smart JIT compiler, you may even get just as
efficient code. You'd have to port malloc(), free(), and the rest of
the standard C library, but that should be pretty straightforward:
they could all be methods of a C emulator class that would also
implement the memory-access primitives.
You'd get memory leaks, invalid pointers, and all the rest of the
problems you get from normal C, but you wouldn't need to change a
line of your legacy code, and you wouldn't be able to jeopardize
anything outside the 'anything goes' byte-array memory space.
Attempts to access values outside the byte-array would throw
an exeption (perhapse we could call it GPF!)
-Eugene
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.