• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why c++ is not plateform independent ?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, if i compiled program on suppose one of the operating
system and run on that. Now, same program i copied (i.e. .cpp file) and compiled on different operating system .
Will it run or not ? If not then why ?
with regards,
prashant dave
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will run, as long as all of the libraries etc that you call are supported on that system (which is often not the case).
It's not platform independant, however, bcause you have to recompile the source code to make it run - a java program you compile can be run without recompilation on any system with a VM. It doesn't matter what system you write/compile it on either.
Grant.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C++ compiles to binary code (.obj, .exe, .dll, a.out etc.). Binary code (Machine code, 0's and 1's) are machine dependent.
Java compiles to byte code which is independent of any machine. It need to be interpreted to binary code by JVM, and executed by the machine.
Roseanne
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Grant Crofton:
It's not platform independant, however, bcause you have to recompile the source code to make it run - a java program you compile can be run without recompilation on any system with a VM. It doesn't matter what system you write/compile it on either.
Grant.


At least, that is the theory. You will quite often find that there are incompatibilities between JVMs for different platforms (or even different JVMs on the same platform).
WORA is nice in theory, but in practice it is more like WODE (Write Once, Debug Everywhere).
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please understand that Java is platform independent but JVM IS NOT.So everytime Java code is interpreted its logically on a same machine.This is not the case with c++.it uses platform specific instructions and hence the m/c code generated by compiler will be diff thus giving rise to incompatability
 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if we're not talking about binary code, it seems to me that there are no guarantees that if you take the SOURCE and try to recompile it on different OS's, that it will work. I THINK that theoretically if you used all ANSI C then it should work, but in any application, especially an enterprise level app which is increasingly common, there are just too many system dependent calls in C/C++. However, seems to me that Java did it right by making these native methods so they leave system dependent stuff up to the system and make the rest "write once, run anywhere". I think some people must find it threatening because they bend over backwards to try to find holes in it, but I can't help but be in awe of the people who designed this lang. Just my $0.02. Admittedly, I'm a newbie to the field.
With Respect,
Matt
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Like everybody has said before C++ is not platform independent and they seem to have covered all the reasons also..
I would like to put a word as to why C++ designers designed C++ the way it is:
C++ designers were forced to maintain backward compatibility with C, whereas Java was a whole new language designed from scratch.
C++ takes the approach that control of efficiency is the most
important issue, so it gives the programmer a choice. Java emphasizes more on simplicity and flexibility.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C++ as a language is not platform independent for the simple reason that C++ is not completely specified, for example, how many bits does an int hold? Second and more importantly, support libraries such as network access and GUI libraries are different on each platform.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also another thing w/C++, if you are using a library created from a compilation on one comiler, it won't necessarily work with code being compiled on a different compiler. (ie COFF vs OMF)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic