Re: C++ -> Java VM compiler

gah@u.washington.edu (G. Herrmannsfeldt)
16 Jan 1997 11:08:53 -0500

          From comp.compilers

Related articles
Re: C++ -> Java VM compiler aszs@enternet.com (1997-01-12)
Re: C++ -> Java VM compiler gah@u.washington.edu (1997-01-16)
Re: C++ -> Java VM compiler kuznetso@MIT.EDU (1997-01-17)
Why Virtual Machines? (was: C++ -> Java VM compiler) p.froehlich@link-m.de (1997-01-25)
Re: Why Virtual Machines? (was: C++ -> Java VM compiler) robison@kai.com (Arch Robison) (1997-01-29)
Re: Why Virtual Machines? (was: C++ -> Java VM compiler) albaugh@agames.com (1997-01-29)
Re: Why Virtual Machines? (was: C++ -> Java VM compiler) nr@adder.cs.virginia.edu (Norman Ramsey) (1997-02-02)
Re: Why Virtual Machines? (was: C++ -> Java VM compiler) Bronikov@srv2.ic.net (Dmitri Bronnikov) (1997-02-02)
[6 later articles]
| List of all articles for this month |
From: gah@u.washington.edu (G. Herrmannsfeldt)
Newsgroups: comp.compilers,comp.lang.c++,comp.lang.java.misc
Date: 16 Jan 1997 11:08:53 -0500
Organization: University of Washington
References: <01bbfca0$a284a6f0$041b6682@tecel> 97-01-094
Keywords: C++, Java, translator

I was looking at the JVM spec with the idea of doing a C compiler.


Presumably through gcc, so maybe similar questions.


Pointer arithmetic is a little tricky, but not that bad. The problem
is that you can't cast pointers and dereference them as a different
type. You can't have a malloc() that returns (char*) and use it as an
(int*). However, if you have malloc_int(), malloc_double(), etc, it
should work. This means a little rewriting of code, but much less
than rewriting in Java.


There is only one kind of pointer variable, but pointers remember what
they point to. An (int*) can be assigned to (char*) and back to (int*)
and used.


Note also that the (int*) type really has to be something like


struct intpointer {
int *origin;
int offset;
};


As there is no way to add to a pointer. The add and dereference are
one operation. But if the pointer type includes the offset, then all
arithmetic can be done on that, and then it is used at dereference.


varargs functions might be complicated in a similar way, but there
may be ways around this, also.


I would be interested to hear from anyone else with any thoughts
about this problem.


-- glen
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.