Hello, I've just started learning c++ using a book i got ( C++ primer plus).
I was reading about source code, object code, compiling and executable code. I got a little confused with the concepts.
Well, my question is: If compiling translates source code into object code for the host computer, and then we make an executable. How can that executable run on other computers beside the host computer the executable was originally compiled for? (suppose the operating system is the same on the computers )
For example, how are like .exe games and programs able to run on other computers beside the one host computer they were compiled on?
The executable and object files are in no way restricted to one computer. The only issues you would have with portability would come from the type of code you use in your program, like the windows library.
Hmm, Different processors read machine language differently right? And if an executable is basically source code compiled into machine language (the object code) along with some startup and library code, then shouldn't a computer with a different cpu/cpu family not be able to use the executable?
C++ is a "portable language" because it follows the ISO (International Standards Organization) guidelines. so as long as a custom library specific to an OS(operating system ex. for windows or Mac) wasn't used to create the source code, then any computer can run it. but there is "Cross-Platform" libraries that can be used on any OS. basically all computers know c++ because it is standardized. Hope that helps.