Reputation: 24500
The source code can be written in any language, but in the end the IDE (Eclipse, Visual Studio, Pycharm, Dr Scheme) translates it to the same binary a computer can understand.
Am I correct? The source code eventually gets translated into SAME binary executable?
I ask about the "flow" of code compiling.
Upvotes: 0
Views: 106
Reputation: 1667
Not quite.
First, there is the matter of CPU architecture and instruction sets. Each CPU family has different opcode tables and base instruction sets, meaning that the "flat" binary generated for an ARM CPU will be fundamentally different than the one generated for an x86 CPU.
Then, there is the matter of file format. Different operating systems place their actual ("flat") binary instructions in various packages. Windows uses the Portable Executable standard to package its binaries, while Linux uses ELF and OS X uses Mach-O.
Finally, with some language implementations, native instructions are never generated at all. For example, JVM-based languages uses the Java bytecode standard to represent architecture-independent operations on a virtual machine. Similarly, Perl and Python have their own bytecode standards that are compiled into at runtime and then interpreted.
Overall, it's very difficult to guarantee that the compilation of a program will produce the exact same binary across multiple systems, even when those systems share architectures. In general, it's better to think about the effects of the binary rather than its actual structure. As long as the compiler is reliable and the language's standard is clear, the resulting program should behave the same no matter how its constructed.
Upvotes: 3
Reputation: 47699
Not entirely correct. First off, the resulting code will not be identical, even for two different "conventional" compilers, since they may optimize code differently, etc. Second, some languages do not necessarily translate directly into machine code.
Java, for instance, translates into "bytecodes" -- instructions for a "virtual machine" which doesn't really exist. In order to execute a Java program the instructions must be "interpreted" by the "bytecode interpreter", a program which simulates the "virtual machine".
Further, even for regular compilers that produce "real" machine instructions, the output format may be in several different forms -- different types of "object modules" which may not "work and play well" with "object modules" from a different compiler (though this is mostly standardized on current systems).
Upvotes: 3