What is C language and What happens when you type gcc main.c?

Sebastian Obando Perez (seobando)
3 min readJun 11, 2020

What is C?

C is a general-purpose programming language which was developed by Dennis Ritchie. It is a medium-level, weakly typed, static data type language.

  • Structure

gcc [options][files].

  • high-level language

It is those languages that are closer to human language than to machine language.

  • Low-level languages

They are languages totally dependent on the machine, that is to say that the program that is carried out with this type of languages cannot be migrated or used on other machines.

What is gcc?

GCC is an integrated compiler of the GNU project for C, C ++, Objective C and Fortran; it is capable of receiving a source program in any of these languages and generating a binary executable program in the language of the machine where it is to run.

G: GNU

C: Compiler

C: Collection

Compilation steps

The compilation process involves four successive stages: preprocessing, compilation, assembly, and linking.

example:

Circle.c: calculates the area of a circle.
Example to show compilation stages.

Code in circle.c:

  1. Prepocessor

They are operations of inclusion, search and substitution of texts, deletion of others …

  • to show the preprocessing the command is used.
gcc -E circle.c > circle.pp
examine changes
more circle.pp

2. Compiler

The compilation transforms the C code into the assembly language of our machine’s processor.

  • to show the compiler the command is used.
This line is used to compile and then to verify
$ gcc -S circle.c
$ more circle.s

3. Assembler

Gives an assembler file with extension s.

  • to show the compiler the command is used.
create the file in object code circle.or from the assembly language file circle.s
$ gcc -c circle.c
where the file circulo.o is created from circulo.c. The file type can be verified using the command
$ file circle.o

3. Linker

The C functions included in our code, such as printf () in the example, are already compiled and assembled in system libraries. It is necessary to somehow incorporate the binary code of these functions into our executable

  • to show the linker the command is used.
The linker known as ID is linked to this code
$ ld -o circle circle.o -lc
NOTE: Using this command generates an error which is due to lack of references
another more direct way is like this:
$ gcc -o circle circle.o
create the executable circle, which invoked by name
$ ./circle
Circle.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sebastian Obando Perez (seobando)
Sebastian Obando Perez (seobando)

No responses yet

Write a response