• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why cant c++ be made architecture,O.S independant.

 
nagarjuna borra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cant we make a c++ program compile to something like bytecode,so that c++ can be made architecture&O.S independant.

All we need to do is get an architecture&O.S specific interpreter as in java.
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good. Start coding one !!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Microsoft Visual C++, you can compile C++ source code to .NET bytecode (that runs on the .NET CLR, which is the .NET version of the JVM). Microsoft has even added extensions to the C++ language called C++/CLI for this.
 
nagarjuna borra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zeeshan Sheikh wrote:Good. Start coding one !!!

what??,a compiler???
no thanks,
Jesper de Jong already answered that.
 
nagarjuna borra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:With Microsoft Visual C++, you can compile C++ source code to .NET bytecode (that runs on the .NET CLR, which is the .NET version of the JVM). Microsoft has even added extensions to the C++ language called C++/CLI for this.


yes,yes,yes.
i forgot that...
why do think c++ isnt competitve to java,even getting the status of arch&O.S independant,just want your opinion,nothing else.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While it's technically possible, it would be more difficult than for Java, and would in the end probably be less platform-independent than Java.

Keep in mind that the Java language was explicitly created with platform-independence and running in a VM as fundamental design goals. Even so, if you're not careful, you can write code that behaves differently or doesn't work on other platforms.

C++ leaves a lot more stuff undefined, is a more complex language to start with, doesn't have platform independence as a goal like Java does, and, as far as I know, doesn't have the same extent of a common core API. Looking at how difficult it can be to port C++ source code from one platform to another, it would be at least that difficult to define a bytecode and C++VM to run it on different platforms.
 
nagarjuna borra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:While it's technically possible, it would be more difficult than for Java, and would in the end probably be less platform-independent than Java.

Keep in mind that the Java language was explicitly created with platform-independence and running in a VM as fundamental design goals. Even so, if you're not careful, you can write code that behaves differently or doesn't work on other platforms.

C++ leaves a lot more stuff undefined, is a more complex language to start with, doesn't have platform independence as a goal like Java does, and, as far as I know, doesn't have the same extent of a common core API. Looking at how difficult it can be to port C++ source code from one platform to another, it would be at least that difficult to define a bytecode and C++VM to run it on different platforms.


thanks ....makes sense,to some extent.
 
Winston Gutkowski
Bartender
Pie
Posts: 10268
60
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:With Microsoft Visual C++, you can compile C++ source code to .NET bytecode (that runs on the .NET CLR, which is the .NET version of the JVM). Microsoft has even added extensions to the C++ language called C++/CLI for this.

Except that platform-independence flies in the face of everything that Microsoft stands for

To paraphrase the old advert for the Model-T Ford: You can run it on any OS as long as it's Windows.

Winston
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a note to say that I thought Jeff Verdegan's reply was brilliantly put. C++ and Java may share some syntactic similarities but are very different programming languages. Trying to make one like the other is a lost cause.

Also, methinks the OP missed Zeeshan Sheikh's point. By saying "All we need to do is ...", nagarjuna borra is over-simplifying matters.

Finally, while Jesper is right, well written C++/CLI code looks nothing at all like C++.
 
Tim Hagberg
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the advantages of C and C++ is that they are not platform independent. This may seem backwards at first, but because C and C++ compile to native code, they can take better advantage of the platforms they are specifically compiled for. With Java, you are running your code over an additional layer of software. While this is nice in that you don't need to learn the idiosyncrasies of each platform you would like to develop for and compile to, you're never going to get the performance you get when writing good C or C++ code.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Hagberg wrote:One of the advantages of C and C++ is that they are not platform independent.


I understand the point you're trying to make, but that's not an advantage in and of itself. Lack of platform independence is a disadvantage. However, what IS the advantage is a side-effect of platform dependence--specifically the point that you bring up that purpose-built tools can generally perform their intended function better than a general tool.

It's a subtle difference, but I think it's worth pointing out.

you're never going to get the performance you get when writing good C or C++ code.


That blanket statement simply isn't true any more. Plenty of real-world apps can perform just as well written in Java and running under a JVM as they would written in C/C++ and running natively.

The main advantage C/C++ has now isn't performance (at least not in general, although I'm sure that's still true for certain use cases). It's the fact that it gives you access to lower level OS-specific features that aren't available in pure Java. If you need those features, you need to either write your app in C++, or write it in Java and write those pieces in C++, either as JNI/JNA libs, or as external processes.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could this be achieved by using LLVM?
Check Julia Language for example? I'm already a fan!
 
Doug Slattery
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cant we make a c++ program compile to something like bytecode


Maybe I'm missing the point, but wouldn't that be a .o file? Most compilers can build a .o file in a standard format like COFF (I'm showing my age ;) ) which can be linked by compilers on other platforms/OS's supporting the same format.

Even GCC has cross compiler capabilities so you can build say an IBM RS-6000 executable on a Linux x86 platform.

Let's not forget that the JVM is written (mostly) in C and Java is an interpreted language. You still need a platform specific JVM to run your "runs anywhere" java code.

Thanks,
- Doug

-- Nothing is impossible if ImPossible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic