I have fairly basic programming experience with Java and I\'ve tried C++ and Pyt
ID: 659160 • Letter: I
Question
I have fairly basic programming experience with Java and I've tried C++ and Python. While it makes sense for Java, the basic programs I've written in C++ have run just fine on Windows and OS X. I've been able to just send the source file to the other computer, compile, and run. The programs are fairly basic, mostly just basic object oriented stuff I've been doing to try to learn C++.
Obviously though, you can't just compile any C++ program on any machine and have it run fine. At what point does that happen? At what level of complexity does the platform start to matter and the program won't just run anywhere? Is it when you use platform specific libraries? Could a program be made cross platform in C++ just using cross platform libraries?
I've been trying to figure this out on my own but everything I've found either goes over my head or simply doesn't answer the question, much of what comes up are emulators or people asking what languages are cross platform.
Explanation / Answer
At what level of complexity does the platform start to matter and the program won't just run anywhere?
Basically anything non-trivial. If you write a non-trivial program, you will end up accidentally depending on a compiler-specific way that it orders overloads, looks up names, and other complex things. Furthermore, practically all non-trivial programs depend on non-Standard platform-specific behaviour because the Standard doesn't really provide anything except a few containers.
However, non-trivial programs can vary widely in how easy they are to port to another platform. If you programmed it well and stuck to the rules, you can port fairly easily, and bonus if you can abstract the pieces into a library (which may have already been provided for you, e.g. Boost.Filesystem).
Programs mostly only become very difficult to port between platforms if they perform tasks that are inherently platform-specific, for example, writing data to disk with certain atomicity/consistency guarantees, or, if you were a moron and went around doing stupid things that were never what you should have done in the first place, like casting between ints and pointers.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.