Why does C have to be recompiled for each architecture? Doesn't it all end up as bits and bytes and loads and jumps anyway? Doesn't each architecture essentially go through the most basic commands in the same way?

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Quantify "architecture". (Do you think an x86 chip uses the same instructions as a ARM chip, for example.)
– John ParkerAug 11 '13 at 11:14

4

Doesn't each architecture essentially go through the most basic commands in the same way?Not really. Definitely not in the exact same way, which is what platform-independence means.
– Marc ClaesenAug 11 '13 at 11:16

1

Because different architectures work differently, so the binary works differently. Otherwise it'd be like using an nVidia driver for an ATI graphics card!
– OMGtechyAug 11 '13 at 11:17

5 Answers
5

Different CPUs have different instruction architectures (e.g., x86 vs ARM).

Early Macs used the Motorola 68k architecture; later ones used PowerPC; and still later ones used x86. During each of these transitions, developers had to ship their executables as fat binaries, which would contain object code for both architectures.

Current x86 CPUs have 32-bit and 64-bit modes.

This is why you have 32-bit and 64-bit versions of Windows, Ubuntu, etc.

Different operating systems provide different system calls, libraries, etc.

Different OS versions can provide different system calls, libraries, etc. also (although OS vendors do aim to be backward compatible as much as possible).

Even on the same operating system, the calling convention is not guaranteed to be the same between different compilers.

Even on the same OS, different executable file formats may be in use. For example, on many Unix systems, a.out used to be the format used, but most eventually switched to ELF. During the transition period, libraries had to be provided in both formats.