I'm learning C and I don't understand what factors determinate the needed compiler and why.
Let's say I'm having C code that is a little console application and I want to compile it for a specific platform. This platform would have a specific OS and instruction set.
How does the instruction set affect which compiler is needed? Does it depend on the actual instruction set or only on its register size (16/32/64bit)? If it depends only on whether it is 64bit or 32bit, couldn't the instruction set look different and the machine code thus be not working? I'm confused about this because there are always 32bit and 64bit versions of an applicaiton offered, even though there are several possible instruction sets.
Does the OS running on top of a specific instruction set affect which compiler is needed and why? Isn't the machine code the same if the CPU is the same?
UPDATE
Thanks to everybody who's answered. My final conclusion
How does the instruction set affect which compiler is needed?
The compiler needs to produce different instructions if the processor has a different instruction set. Most compilers support multiple instruction sets so you may not need to change the compiler just because the instruction set changes.
Does it depend on the actual instruction set or only on its register size (16/32/64bit)?
Both.
If it depends only on whether it is 64bit or 32bit, couldn't the instruction set look different and the machine code thus be not working? I'm confused about this because there are always 32bit and 64bit versions of an applicaiton offered, even though there are several possible instruction sets.
While there are different instruction sets x86 and x64 dominate the desktop-market and most software vendors do not see a need to support anything else.
Does the OS running on top of a specific instruction set affect which compiler is needed and why? Isn't the machine code the same if the CPU is the same?
The instruction set is the same but the way to talk to the operating system is different. In principle you can run a windows application on a linux if they both run on the same instrucion set, however, the application will say "windows open that file" and linux has no idea what to do. The wine project fills the gap and runs windows applications under linux by translating "windows open that file" to "linux open that file" which gets complicated if more windows specific functions need to be implemented.