wood burning stoves*
The moose likes C / C++ and the fly likes why cant c++ be made architecture,O.S independant. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "why cant c++ be made architecture,O.S independant." Watch "why cant c++ be made architecture,O.S independant." New topic
Author

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

nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
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

Joined: Nov 20, 2011
Posts: 144

Good. Start coding one !!!


MySQL Blog
http://mysqlearner.blogspot.com/
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
Zeeshan Sheikh wrote:Good. Start coding one !!!

what??,a compiler???
no thanks,
Jesper de Jong already answered that.
nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Jan 14, 2012
Posts: 41
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

Joined: Mar 17, 2011
Posts: 7484
    
  18

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 257

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++.


"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Tim Hagberg
Greenhorn

Joined: Jan 29, 2010
Posts: 12
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Nov 08, 2003
Posts: 3476

Could this be achieved by using LLVM?
Check Julia Language for example? I'm already a fan!
Doug Slattery
Ranch Hand

Joined: Sep 15, 2007
Posts: 294
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why cant c++ be made architecture,O.S independant.
 
Similar Threads
static methods
Design Patterns
All about static methods
override
abstract