C++ to java code converter

R

Ravi

Do we have anything that could convert C++ code to java
code?
To what extent are such tools reliable?

TIA.
 
V

Victor Bazarov

Ravi said:
Do we have anything that could convert C++ code to java
code?
To what extent are such tools reliable?

This question is off-topic in comp.lang.c++ newsgroup.
Just to let you know...
 
T

Tor Iver Wilhelmsen

Ravi said:
Do we have anything that could convert C++ code to java
code?
To what extent are such tools reliable?

If the C++ code is so simple that it can be expressed in Java (like no
operator overloading, no pass-by-value, pointers and not references)
it's just as easy to just "translate" by hand.
 
R

Ravi

If the C++ code is so simple that it can be expressed in Java (like no
operator overloading, no pass-by-value, pointers and not references)
it's just as easy to just "translate" by hand.

I don't want anything perfect but something that could get
close for simple C++ programs.

Is there anything that could convert java code to C++ BTW?
 
M

Mike Wahler

Ravi said:
I don't want anything perfect but something that could get
close for simple C++ programs.

Is there anything that could convert java code to C++ BTW?

I think the best response to your question is to answer with
more questions:

Why do you want to do this? What specific problem are you trying
to solve?

My views about this:

The only really justifiable reasons for choosing one language
over another is that one has determined that it is best suited
for a particular task, or if an implementation of the language
in which existing code is written is unavailable for the target
platform.

Automated conversions usually result in very poor code, with
regard to effective exploitation of the target language's
features.

An effective conversion is done by obtaining or deriving the specifications
of the program, and applying the new language's
features in writing the new code, and not using the old code at
all (except perhaps as a reference).

Referring to comments (if any) in the old code can help, e.g.
with regard to elaboration upon the specification, and descriptions
(if any) of particular techniques used to implement a given
task. More often than not such techniques won't translate well
directly to the new language, but the new language might feature a technique
more 'natural' (and typically more efficacious) with that language.

This last is the reason why I reject the idea of using such
automated conversions as aids to learning the new language
(a guess as to a/the motivation of your query).

None of this is topical here anyway.

-Mike
 
S

Socketd

Do we have anything that could convert C++ code to java
code?
To what extent are such tools reliable?

Once I planed to write such a program, because I had the write Java
programs for my OO-programming class and I really wanted to use C++. I
found that it would be impossible to write such a program.

C++ -> java is not possible because C++ has a lot of features Java
doesn't have. Like operator overloading, friends and multiple
inheritance (this is just from the top of my head, I am sure there is
more).

Java -> C++ is also a mess because Java too have a lot of
features/classes C++ doesn't have. Like a GUI library and data/time
classes, just to name a few. There is also the pointer/reference
problem. Also from a java program you can't see when heap objects should
be destroyed, because java (unlike C++) uses a garbage collector.

So sorry, there is no easy way out.

br
socketd
 
R

Roedy Green

Do we have anything that could convert C++ code to java
code?
To what extent are such tools reliable?

Seriously just compile and fix the errors. Use global search and
replace.

The string handling model is C++ works on the notion of 8-bit null
terminated strings. In Java it uses 16-bit counted strings. The ways
you do processing are very different. You really have to devine the
end intent of the code rather than mimic how the old code did it.
 
G

Gregg

The string handling model is C++ works on the notion of 8-bit null
terminated strings.

No, it does not. The C++ string is a parameterized type. It can have any
integral type as its underlying character. There is no requirement that it
be null-terminated, either.

You are thinking of C-style strings and literals, which, although null-
terminated, are not limited to 8 bits either.

Gregg
 
P

Paul Lutus

Ravi said:
I don't want anything perfect but something that could get
close for simple C++ programs.

Is there anything that could convert java code to C++ BTW?

To answer both questions, there really is no way to automatically convert
C++ -> Java or Java -> C++. They are too different in design for a
conversion to be anything but hand-coded.
 
S

Steven C.

Do we have anything that could convert C++ code to java
code?
To what extent are such tools reliable?

TIA.

--
main(){char s[40]="sbwjAeftqbnnfe/dpn!ps!CSbwjACjhgppu/dpn";
int i;for(i=0;i<39;putchar(s[i++]-1));return 0;}
________________________

Yes, I can!
 
R

Ravi

I think the best response to your question is to answer with
more questions:

Why do you want to do this? What specific problem are you trying
to solve?

Well, definitely there cannot be something that does this
perfectly. Now how would you expect to run a multithreaded
java code with c++ or for that matter have a function
outside a class in java? Agreed.

I have a program which is written in C++. I intend to do
something similar on Java. Now I was just looking for
something that could convert very simple c++ code to an
equivalent messy java code to start with, then I could fine
tune the code to make it compile correctly in Java.
 
P

Paul Lutus

Ravi wrote:

Well, definitely there cannot be something that does this
perfectly. Now how would you expect to run a multithreaded
java code with c++ or for that matter have a function
outside a class in java? Agreed.

I have a program which is written in C++. I intend to do
something similar on Java. Now I was just looking for
something that could convert very simple c++ code to an
equivalent messy java code to start with, then I could fine
tune the code to make it compile correctly in Java.

The solution is simple. Skip phase one above, and move right into phase two.
Just make a copy of the C++ source file, rename it *.java, and start
working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top