Manobina Paul
3 min readDec 28, 2020

COMPILING WITH C-LANGUAGE ->INSIDE THE PROCESS

C is a general-purpose ,structured programming language. It resembles other high level structured programming languages such as Pascal and Fortran. C also contains certain additional features. However, that allow it to be used at a lower level, thus bridging the gap between machine language and the more conventional high level languages. This flexibility allows C to be used for system programming(e.g., for writing operating systems)as well as for application programming (e.g., for writing a program to solve a complicated system of mathematical equations).Thus it needs a compiler to convert it into an executable code so that the program can be run on our machine.

COMPILE AND RUN A C-PROGRAM

In this article you will learn how to run a C — program in command prompt/line on a windows operating system. You will need a C-programming compiler(here gcc)to do this.

If you use windows computer, command gcc-v can be run to check if it’s already installed. After installation it will display a host of information starting with the sentence “using built-in-specs”.

gcc-v

STEP-1

Write a C-program using editor.

#include<stdio.h>

Int main()

{

Printf(“Hello World!”);

Return 0;

}

STEP-2

Open Command Prompt/line.

Open the command prompt by clicking start button->All Apps->Windows system floder->click command prompt.

STEP-3

Go to the source code directory,change our directory to where you have your C program (HelloWorld.c ).You can do that by using the command ‘cd ‘.

cd filename

STEP-4

Compile the source code

Run the command”gcc”(the C -compiler) followed by the full name of your program(HelloWorld.c)in the command prompt.

This will compile your source code and create an executable file.

gcc name of file . c

gcc HelloWorld . c

note: The executable file named itself probably like ‘filename.exe’.

-> Then compile it using below command

-> cc filename.c or

-> cc filename. c -o filena _ out or

-> cc filename . c -wall -o filena _ out

The option -wall enables all compiler’s warning messages.This option is recommended to generate better code. The option -o is used to specify output file name.If we do not use this option ,then an output file with name a.out is generated.

STEP-5

Run your program.

In this step we will run our program(the executable file) in command prompt.

./filename

INSIDE THE COMPILATION PROCESS

There are four phases for C program to become an executable.

1. PRE — PROCESSING

2. COMPILATION

3. ASSEMBLY

4. LINKING

PRE-PROCESSING

The pre-processor basically substitutes all the pre-processor directives in the original .cpp file or .c file with actual library code that implies that directives. e.g library code is substituted for #include or #define directives. After that the file generated basically gets the substituted and get a extension of ‘.i’ file.

COMPILATION

The compiler basically translate the high level language .It checks the grammer/syntax of the source code . If found to be corrected then the source code is converted to assembly code i.e ,file extension .s file.

ASSEMBLY

Assembly code converts the assembly level language i.e, .s file to machine level language.It is converted into object file and it is generally in binary format and it’s file extension is .o or .obj file.

LINKING

Linker generally combine one or more than one object file to a executable file it converts .obj or .o file to .exe file .After the conversion the format becomes binary and the file extension is .exe file.

A linker checks whether all the variables or functions are defined or not .If defined then the linker links the object files with the object files in the library to create an executable file.

THANKS FOR READING THIS ARTICLE .HOPE IT’S HELPFUL TO YOU ALL ! KEEP UP THE LEARNING, AND IF YOU WOULD LIKE MORE PROGRAMMING & ALGORITHMS ANALYSIS, MOTIVATIONAL TOPICS PLEASE DO VISIT.

COMMENT BELOW IF YOU HAVE ANY DOUBTS REGARDING THIS AND ANY OTHER QUARIES .ALSO SUGGEST MORE INTERESTING TOPICS THAT YOU WANT TO KNOW ABOUT.

Manobina Paul
Manobina Paul

Written by Manobina Paul

B.Tech in Electronics & Communication Engineering. Ability to work with C, Java, HTML, Python, and SQL. Interested in technology and innovative ideas.

No responses yet