Underneath the Hood of the Compiler
Now that you set up your enviroment, you are ready to program.
But , WAIT right there.
To understand programming we need to know what happens underneath the hood of the compiler as this gives us a better apsect of whats happing to the code and it might help in the future projects you budding programmers will certainly make.
Keep in mind that a computer can only understand binary and binary only.
Right now, I think most of you will be going "What's Binary ?", and then have a 10-minute google search to find out.
Well, I'll spare you the trouble and tell you anyway.
A computer is very dumb, as it can only understand a sequence of one's and zero's called machine code.
So a computer can't actually understand C++, C or any other language.
So this is why we need a compiler, to translate code from C++ to machine code
*Note: The same process happens in the C compiler GCC
Preprocessing
The preprocessor is a tool that takes a look at the code and see's any symbols like:
Code: Select all
#includeCode: Select all
#defineAnd if it does it replaces bits and bobs of the code until every thing is fine and dandy.
Its like a spell check but for the programming language.
***Note: The code has not started compiling
Compiling
As soon as the preprocessor is done with the source code, then the compiling begins.
The compiler converts the C++ code into Assembly, and creates several optimisations and to stop the program from consuming too much memory and make the program faster.
So the compiler creates .s files form the generated Assembly.
Assembling
Once the compiler has converted all the C++ code into assembly, the assembler (an assembly compiler) takes the assembly code and converts it into .o files called object files. This is basicly machine code, but it still has symbols (i.e cout) and has no executable structure so the OS won't be able to recognise it as a executable.
Linking
Once the object code is generated by the assembler, the linker removes all the symbols and links the extra library code needed.
The finished product ,The Executable!!!
Once the linking is finished, the machine code is changed accoring to the target executable which depends on the OS.
The two most common are:
-Microsofts Win32 EXE Excutable
-Executable and Linkable Format (ELF)(This format is used by most POSIX systems and all the Playstation consoles)
Now after this insight are you a little bit more knowledgeable about what goes on underneath the hood?
<<Prev | Next>>
Advertising