LET'S TALK ABOUT C - Hello, World / Steps of compilation :

LET'S TALK ABOUT C - Hello, World / Steps of compilation :

C is a compiled language.

C source files are by convention named with .c extension and we use the command “gcc” to compile C source files. (GCC stands for GNU Compiler Collection.)

Four Steps of Compilation: preprocessing, compiling, assembly, linking.

- Preprocessing is the first step. The preprocessor obeys commands that begin with # (known as directives) by:

* Removing comments

* Expanding macros

* Expanding included files

If you included a header file such as #include <stdio.h>, it will look for the stdio.h file and copy the header file into the source code file.

- Compiling:

Compiling is the second step. It takes the output of the preprocessor and generates assembly language, an intermediate human readable language, specific to the target processor.

- Assembly:

Assembly is the third step of compilation. The assembler will convert the assembly code into pure binary code or machine code (zeros and ones). This code is also known as object code.

- Linking:

Linking is the final step of compilation. The linker merges all the object code from multiple modules into a single one. If we are using a function from libraries, linker will link our code with that library function code.


#include <stdio.h>

int main(void)

{

   printf("Hello, World!\n");

   return (0);

}


At the shell prompt, enter the command “gcc main.c” and hit Enter. If it successfully compiles, the shell prompt will be displayed again. If it does not compile, it will display error message(s).

After main.c is compiled, type the command “ls” to list your directory contents and you will see an executable file named a.out.

Stay tuned for the next blog!

To view or add a comment, sign in

More articles by Danielle Serafim

  • LET'S TALK ABOUT: Internet of Things (IoT)

    The internet of things (IoT) is a system of computing devices, mechanical and digital machines, objects, animals or…

  • Recursion in computer science

    According to wikipedia recursion is a method of solving a computational problem where the solution depends on solutions…

  • Python3: Mutable, Immutable... everything is object!

    In Python no matter the case, everything has a series of attributes(built-in) that can be accessed and modified, we…

  • LET'S TALK ABOUT: Libraries in C

    What is a Library and why and how is it used? What is Static and Dynamic Library? A library is exactly like an…

  • LET'S TALK ABOUT: What happens when you type 'ls -l *.c' in the Shell

    We could say this command is to see a type of list and with the '*.c' list's all the files ending with '.

  • LET'S TALK ABOUT C - Static libraries

    A static library is an archive file containing object files that remain static until the program is recompiled. Why do…

    1 Comment
  • LET'S TALK ABOUT LINUX SHELL

    WHAT IS SHELL? Shell is a UNIX term for an interface between a user and an operating system service. Shell provides…

Explore content categories