Am I coding for an OS or the Processor? Am I coding for an OS or the Processor? c c

Am I coding for an OS or the Processor?


Both; kind of.

The actual instructions don't really differ across Windows and Linux as they are compiled down for a single CPU architecture (x86).

However, a binary is more than just code that runs on bare hardware. For instance, it also contains information that tells the operating system how to load the executable and its dependencies. The binary is packaged in a specific format. This format can be different in different operating systems.

Besides that, the operating system provides some services to the applications (through system calls and APIs). The services that operating systems provide, and the way they can be used varies from an operating system to another.

These reasons contribute to the fact that most of the time a native binary depends on both OS and CPU architecture it's compiled for.


Answer to the updated question:

C++ Standard doesn't require anything about the nature of the compiled target. It just specifies compatibility requirements at the source level. Consequently, if you stick to the standard libraries, you'll be able to use the same source code to compile on platforms that offer a conforming C++ implementation. The standard doesn't say anything about binary portability. As I mentioned above, the primitive system calls that operating systems provide can vary and the actual implementation of the standard library depends on the way those system calls are provided by the OS.

In order to run a Windows binary on Linux, you need to use some sort of emulation like Wine which understands Windows binary format and simulates Windows API for applications.


1) The processor architecture (plus the targeted libraries static or dynamic)

2) Yes

A 32bit windows application will run on a Windows 64bit platform as WOW.


If your (windows) compiler's target architecture is x86 (32-bit) then it can run on any 32 bit and 64 bit Windows 7. But if its x86-64, it will only run on 64 bit Windows 7.