4 Ways You Can Organise Your TODOs as a Software Engineer

TODOs are a tricky subject for developers. Many codebases are guilty of having TODOs linger around while nobody knows who’s responsible for a TODO or even has the required context to tackle it. Yet…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Compilation steps

The compilation is the process to translate a high human-readable programming language into a language that can be understood by the computer: ones and zeros, that is saved in an executable file. The program that makes that process is called ‘compiler’.

The compiler GCC can translate languages like C, C++, Objective C, and Objective C++. Here we talk only about C compilation.

Basic usage

To use GCC you need to write the name of the program and the name of the program in the command line.

If the code doesn’t have problems, GCC is going to create an executable file with the predefined name “a.out”, that you can execute like this:

Name your file

To give it a personalized name you can use the flag -o at the end of the sentence like this:

The flag -o is the only one that is written at the end of the command line.

Flags to review the code

You could wish to add some flags to be sure that your code not only works but is also well written. Some of them are:

Now, we are going to describe the compilation process step by step:

The first thing that GCC makes is run the PRE-PROCESSOR. It takes the source code, removes the comments, includes headers, and replaces macros with code ( keep reading to understand these). You can ask the preprocessor to stop at the end of this stage with the flag “-E”.

The comments let the people understand what your functions need as input (parameters), what the function does with these parameters, and what it returns in case of success or failure. It means that when someone else needs to use that function can read those comments and be ready to use it. They look like this:

Comments can be inside the function, too. They can inform what the code does, or they can be used to avoid some lines in the compilation.

A header file tells the compiler how to call some functionality, It means, which is the name of the function, which are the inputs needed and the output it generates. But headers don’t include the process made in the middle of the inputs and the outputs. Think that the functions are your friends and the header is like an agenda where you save the numbers of your friends, so you can call them when you want to. The header is included in the same subdirectory as the source code, and on the inside, the header files are human-readable, with the same syntax as the source code.

A macro is a fragment of code that is given a name. They can define constants that are going to be used during the process but they can’t be changed during the process implementation, like in the first example the constant PI. They can define some kind of special function, too. In the second example is defined the process to get the area of a circle of diameter r.

The output of the preprocessor is received and transformed in assembly code.
A human-readable language, a little bit harder than C. Let's see an example of the same function written in C, and written in assembly:

The assembly code gives more specific and detailed instructions than a more human-readable language.

To see your own functions translated to assembly code, use the flag -S.

The assembler translates the assembly code into binary.

The previous example in this stage generates a file with the extension ‘.o’ named ‘object code’. It is a binary file, but an editor as emacs, vim, or nano, will not show the ones and zeros, they will will show something like this:

If you want to see the file in zeros and ones, you can use the command xxd:

It is a little bit long: 204 lines, just to return the number 1.

Finally, the linker adds the environment variables, function definitions, and settings required to run the code, creating a very big executable file. Keep reading to see what these mean.

To complete the linking phase, you can compile without any flag:

By default, it will create a new executable file called a.out. Execute it like this:

The linker will look for the environmental variables mentioned in your code, for example:

And will bring the content of the variable, in my case:

You can see all your environment variables with the command printenv:

and see the content of one of these with echo:

All these variables can be taken into account inside your functions.

About function definitions, the compiler already knows that we called the library stdio.h, and we used the function putchar. But it only knows the prototype that we included in the header. The linker now searches the body of the function putchar and includes it inside our program.

I am a passionate software developer from Holberton School and a Psychologist from the National University. During all my life I have been developing valuable professional skills as being a good listener, critical thinker, and team player. I have been consistently recognized as a very intelligent and empathic person. Whether on work or academic life I want to create meaningful experiences and inspire my partners. I am consistently dedicated, and curious.

I hope you enjoyed this reading!

Made by Natalia Vera Duran.

Add a comment

Related posts:

Filmmaking Danger Beyond Guns

The recent and tragic events on the set of Rust leaving one person dead and another injured left me saddened but not surprised. Film production is dangerous even under the most minimal of…

Sheltering

When I cover my eyes — sending messages encourage incursion, invasion — the collapse of the roof itself to the shelter of materials — lives caught brightening geriatric glazed — absence of the return…

Does University Really Lead to Success?

How many times has that phrase been uttered by university students and graduates across Sydney? How many times has that phrase been the reason why countless plans have been cancelled? As employment…