| | |
Why different compilers for different OS?
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
Hello, I'm novice in computer science , please bear with me.
I have studied some embedded systems and now I have just started learning PC programming in C . My question is when one complies a C program it is converted into a binary file right? That is machine language, 1s and 0s executable by the processor? But if that is the case then why must we use different compilers for different operating systems running on the same platform? A program compiled for Windows should run on Linux too? Why is that not so?
I have studied some embedded systems and now I have just started learning PC programming in C . My question is when one complies a C program it is converted into a binary file right? That is machine language, 1s and 0s executable by the processor? But if that is the case then why must we use different compilers for different operating systems running on the same platform? A program compiled for Windows should run on Linux too? Why is that not so?
-6
#2 Oct 22nd, 2009
Because there are 2 parts to this, compiling and linking.
Every processor or processor family has its own machine code instruction set. The compiler makes object code, and the linker combines them together into an excutable consisting of machine (native, unmaneged) code conforming to that instruction set.
A native (hosted) compiler produces executables which run directly on the same type of CPU architechtite + operating system that the compiler runs on. A cross compiler howber is designed to run on a different platform (e.g you could build UNIX binaries for the SPARC CPU under Windows using a cross comiler)
Even if they were a unified executable format betwen say, unix-like systems and windows, it wouldnt work because they do things differently. For example, the method for printing a character to the screen would be handled differenely between OSes. Also the character would be a different number of bytes depending on CPU and OS.
Every processor or processor family has its own machine code instruction set. The compiler makes object code, and the linker combines them together into an excutable consisting of machine (native, unmaneged) code conforming to that instruction set.
A native (hosted) compiler produces executables which run directly on the same type of CPU architechtite + operating system that the compiler runs on. A cross compiler howber is designed to run on a different platform (e.g you could build UNIX binaries for the SPARC CPU under Windows using a cross comiler)
Even if they were a unified executable format betwen say, unix-like systems and windows, it wouldnt work because they do things differently. For example, the method for printing a character to the screen would be handled differenely between OSes. Also the character would be a different number of bytes depending on CPU and OS.
Last edited by jbennet; Oct 22nd, 2009 at 11:22 pm.
If i am helpful, please give me reputation points.
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 4
0
#5 Oct 23rd, 2009
•
•
•
•
There are lots of different compilers for the same os too -- its called competition.
I think an easy to grasp example is how an OS stores Data. This would be the FileSystem. Each OS writes files with a header containing meta-data called an i-node. Files written in a different OS would have different I-nodes and therefore, impossible to read properly. A compiler is a set of files and a program is a set of files. For a compiler to correcly associate the data correctly, those files should be written in - for the propper OS.
Most OS code is written in C since it is less painful to write then assembly but low-level enough that you can do specific kernel-level operations.
Another interesting thing to note is that, compilers don't necessarily have to be tied to a specific OS The Church-Turing thesis states that any computable function (i.e. a program) can be computed by a turing machine (a theoretical computer). This means that any software, theoretically, can run on any machine. This is how emulators work. If you've played MAME games or perhaps downloaded an amiga chipset emulator. This is also why OpenGL runs system independantly. It's not that compilers have to run on a specific OS, it just means that no one has bothered to implement the overhead to ensure that they can.
Another good example would be PERL. When I write a windows PERL program in active perl, the statemnt system("pause") does just that. When I run the same program on my Solaris SPARC workstation, it has no idea what the pause command does
![]() |
Similar Threads
- learning C, working around code for different compilers (C)
- C++ Compilers (C++)
- compilers in C (C++)
- compilers for c++ (C++)
Other Threads in the Computer Science Forum
- Previous Thread: help with face recognition technique
- Next Thread: Programming
| Thread Tools | Search this Thread |
advertising android apple assembly betatesting billgates bing bootloader bsd bug bugs business c/c++ ceo choose chrome chromeos compiler computer computers cool developer development embedded error fiji freebsd games gnome google gpl hardware high-performance htc ideas iphone java karmic kernel koala launch leopard linux mac magic malware microsoft mobile mobilephone netbooks news onlineapps opensource operatingsystem operatingsystems os osx pc phone program programming ps3 redhat risc search security server software softwaredevelopment sony sophos steveballmer super technology tiger tools ubuntu unix upgrade virtual vista windows windows7 windowsxp xp







