0

C++ compilers converts code into machine language, which makes it platform dependent, while Java compiler converts it into bytecode and which in turns runs on JVM which is developed for every OS(I suppose). This makes Java platform independent. My question is, is any software and compiler, instead of regular C++ compilers, available, which converts C++ into something like bytecode instead of machine code, and then run it on a virtual machine like JVM, and thus implementing write once, run anywhere concept? If no, would implementing such a way of compiling C++ code be beneficial in terms of platform independency, and even retaining all the present features of C++? (For ex, being able to do manual memory management instead of garbage collection)

Sahil
  • 59
  • 9
  • Sounds off topic, but in theory it's possible. In practice C++ is always complied from scratch for each new OS/hardware platform. Note: Java depends on the JVM which is a platform. – Peter Lawrey Dec 03 '15 at 18:09
  • main feature of C++ is efficiency and afaik running a virtual machine is by far less efficient than directly compiling for the target platform – 463035818_is_not_an_ai Dec 03 '15 at 18:22
  • @tobi303 Java also compiles to a target platform i.e. native code and can be as fast as C++. – Peter Lawrey Dec 03 '15 at 18:25
  • If I'm more concerned about portability and less about performance , then? – Sahil Dec 03 '15 at 18:26
  • Yes, you can run Java on any platform for which there is a JVM. And guess what language that JVM is written in? (Hint: it's **not** Java). – Pete Becker Dec 03 '15 at 18:52
  • You can use a source-to-source compiler like emscripten to convert C++ to asm.js (a subset of javascript) which can be run with, e.g., node.js - thus realizing write once, run anywhere. Such applications can even be executed by regular web browsers (and demos for applications ranging anywhere in complexity from simple hello worlds to 3d games can be found online). – Christoph Sommer Dec 04 '15 at 00:24
  • @Pete Becker. Yes dude, it's our most awesome C++ – Sahil Dec 04 '15 at 01:31

0 Answers0