Sorry for the newbiness of this question. I am planning to go back to school and get a computer science degree, as I have come to realize that many of my interests and skills are in this area. But for now the very low level operations of a computer are a complete mystery to me.
I began teaching myself c++ yesterday, and wrote some very basic stuff, like what I included below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
using namespace std;
int main()
{
int a, b;
float result, c;
cout << "setting variable a..." << endl;
a = 5;
cout << "a = " << a << endl;
cout << "setting variable b..." << endl;
b = 2;
cout << "b = " << b << endl;
cout << "setting variable c..." << endl;
c = 1.618;
cout << "c = " << c << endl;
a = a - b;
cout << "a minus b = " << a << "..." << endl;
result = a / c;
cout << a << " divided by c = " << result << endl;
cout << "K shoots!" << endl;
return 0;
}
|
I then compiled it on my linux machine using the g++ command where it launches from the shell flawlessly. I run alot of different operating systems on my machines, and would love to be able to write stand alone software that I could run on any of my devices. So as an experiment I took the compiled binary and ran it from .cmd on an older xp machine. It relays the following error:
'16 bit MS-DOS subsystem
C:\\WINDOWS\system32\cmd.exe -nameofmyprogram
The NTVDM CPU has encountered an illegal instruction.
CS:0530 IP:0537 OP:63 2b 2b 2e 73 Choose 'Close' to terminate program'
(I'm assuming that if I compiled the source on the xp machine that it would run just fine, but I have not gone through the trouble of getting a c++ compiler onto it.)
Again, I really don't understand how the CPU operates, but I was under the impression that binary was a univeral language, and that compiled c++ programs should be cross platform.
I guess my question boils down to this:
1)Is this a CPU architecture incompatibility, or an OS issue?
2)Is there a valid option for creating a c++ binary that works on a foriegn OS or CPU besides compiling it on the destination machine?
I'm trying to learn all this stuff with the intention of (hopefully) making it my career one day, so by all means get as detailed as you want. Thanks!