What is a Compiler? Compilers in C Explained for Beginners (2024)

/ #Compilers
What is a Compiler? Compilers in C Explained for Beginners (1)
Tiago Monteiro
What is a Compiler? Compilers in C Explained for Beginners (2)

Did you know that it is thanks to compilers that software exists?

Exactly – compilers are very important, and some form of a compiler exists in all programming languages.

But, what is a compiler? What do they do exactly?

This article will teach you:

  1. What a compiler is with an analogy.
  2. The basic history of C compilers.

Don’t worry, you don’t need programming experience to understand what a compiler is.

You just need to understand the concept first, and then if you want, you can go for the technical definition.

1. What is a Compiler? An Analogy

What is a Compiler? Compilers in C Explained for Beginners (3)

Imagine that you are learning a language (French, Spanish, or Portuguese) and you want to know the meaning of a word or sentence.

To do that, you are going to use Google Translate.

The first step is knowing what you will type into Google Translate and checking if it is typed correctly.

The second step is choosing the language you want to convert. For many readers, it will be English.

The third and final step is just getting to know what that sentence means in English.

Essentially, you just typed in Google Translate a sentence or word you did not understand. Google Translate translated that sentence into English.

What is a Compiler? Compilers in C Explained for Beginners (4)

The same thing happens in programming.

In this case, we are using the C language.

The first step you must take is to know what you will type in the .c file and if it is typed correctly.

In this example, the file is called main.c.

#include <stdio.h>int main(){printf("Hello World"); return 0;}
What is a Compiler? Compilers in C Explained for Beginners (5)

The second step is to compile it. It will be compiled according to the compiler you have.

gcc -o main main.c -Wall
What is a Compiler? Compilers in C Explained for Beginners (6)

The third and final step is simply getting to know the output of the program – to make sure it is running like we want.

Quick note: if you want to know what each word in the command line terminal means, please check out the “More…” section in this article!

What is a Compiler? Compilers in C Explained for Beginners (7)

You can see in the image below a visual explanation of the compiling process:

What is a Compiler? Compilers in C Explained for Beginners (8)

How C Compilers Work

What is a Compiler? Compilers in C Explained for Beginners (9)

Over the years, tech has evolved at an incredible pace. The same applies to compilers.

The C compiler has, over time, evolved into many versions.

Just like PlayStation – there is the Playstation 2, Playstation 3, Playstation 4, and so on.

The same is true for C compilers. Once it was standardized, many versions were created:

  • C89/90, a version of C once standardized,
  • C99 replaced C89 and C90 in 1999.
  • C11 replaced C99 in 2011.
  • C17 replaced C11 in 2018.
  • C2X will replace C17 in 2023.

Just like with a PlayStation, each new version has new features.

Some people prefer just playing on their PlayStation2.

It’s the same with programmers. For a variety of reasons, programmers may prefer to write and debug C code with the C99 or C11.

More About Compilers

What exactly does “gcc -o main main.c -Wall” mean, that we saw in the code above? Let's break it down piece by piece.

gcc is the command that invokes the compilation process (preprocessing, compilation, assembly, and linking).

-o main indicates that the name of the executable file created by the compilation of "main.c" is going to be called "main".

main.c is the name of the file to be compiled.

The -Wall option enables compiler warnings. Compiler warnings let you know that something in your code isn't quite right.

This is similar to Grammarly. If Grammarly suggests changing a sentence, you should in most cases change it to make it clearer and more correct.

Otherwise, if you try to change something in a phrase that's already right, it can become illegible.

In the same way, if you ignore warnings in code, it can ultimately cause major bugs and your project might even fail.

What does "Standardized" mean?

So you might be wondering, what does “standardized mean that we saw above?

What is a Compiler? Compilers in C Explained for Beginners (10)

Let's look at it through another analogy. There are many ways to build a house. But there is a certain way that is generally both the most efficient and the safest.

Because of this, people and organizations must agree that there is a standard way of building a house.

The process of creating that standard is called standardization.

When a set of rules becomes a standard, the set of rules becomes standardized.

This set of rules can be a law, a certificate, or just a basic convention used by workers in a certain field.

The same applies to C compilers.

It is standardization that helps people agree on how things should be done, whether it is C compilers, car components, or anything else.

Standardization can also help people agree on which version of C to use. C compilers are an example.

The C compiler has long been considered a fundamental component of software development.

As a result of the C compiler standard, developers can compile and run other people's code without worrying that their compilers will not work.

In order to create such an important building block of the industry, there must be an organization that is responsible for establishing standards

Many organizations create and manage standards. In the case of C compilers, ISO (International Organization for Standardization) manages the standards.

As long as the ISO manages future C compiler standards, programmers and companies can develop reliable software.

Wrapping Up

Thanks for reading! Now you understand:

  • What a compiler is
  • The basic history of C compilers
  • What standardization means

Here is the GitHub repository with the code and image files I created.

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

What is a Compiler? Compilers in C Explained for Beginners (11)
Tiago Monteiro

3º year electrical and computer engineering student at Nova School of Science and Technology in Portugal | Vice Chair of IEEE NOVA SB | IEEE NOVA SB represents IEEE | https://www.ieee.org/

If this article was helpful, .

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

ADVERTIsem*nT

What is a Compiler? Compilers in C Explained for Beginners (2024)
Top Articles
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6185

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.