0% found this document useful (0 votes)
2 views

Lect 4 Programming Logic Using ‘C’ Compilation Process of C Program

The document outlines the compilation process of a C program, detailing the four major steps: preprocessing, compiling, assembly, and linking. It explains the role of the preprocessor, compiler, assembler, and linker in converting source code into machine code. Additionally, it includes a simple example of compiling a 'Hello, world!' program using the GCC compiler.

Uploaded by

nayecool37
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lect 4 Programming Logic Using ‘C’ Compilation Process of C Program

The document outlines the compilation process of a C program, detailing the four major steps: preprocessing, compiling, assembly, and linking. It explains the role of the preprocessor, compiler, assembler, and linker in converting source code into machine code. Additionally, it includes a simple example of compiling a 'Hello, world!' program using the GCC compiler.

Uploaded by

nayecool37
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Programming Logic Using ‘C’

BCAC0001
Lect-4 Compilation Process of C program
Presented by:
Atul Kumar Uttam
Assistant Professor
Computer Engineering & Applications Department,
GLA University, Mathura
atul.uttam@gla.ac.in, +91-8979593001
Compilation process in c
• Compilation
– process of converting source code in to machine code (binary 1’s and
0’s)
• CPU can understand and execute only machine code.

• 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 and it is a compiler


system produced by the GNU Project.)

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compilation process in c
• Four major steps of Compilation:
– preprocessing
– compiling
– assembly
– linking

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compilation process in c

https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html
BCAC0001 Programming Logic Using C
Atul Kr Uttam
1. Preprocessing
• The preprocessor obeys commands that begin with # (known
as directives) by:
– removing comments
– expanding macros
– expanding included files
• #include <stdio.h>
– it will look for the stdio.h file and copy the header file into the source
code file.
• The preprocessor also generates macro code and replaces
symbolic constants defined using #define with their values.

BCAC0001 Programming Logic Using C


Atul Kr Uttam
2. Compiling
• It takes the output of the preprocessor

• Generates the syntax error, if any

• Translate preprocessed code into assembly code

• An intermediate human readable language,

• Specific to the target processor.

BCAC0001 Programming Logic Using C


Atul Kr Uttam
3. Assembly
• The assembler will convert the assembly code into
machine code (zeros and ones).

• This code is also known as object code.

BCAC0001 Programming Logic Using C


Atul Kr Uttam
4. Linking
• The linker merges all the object code from multiple
modules into a single one.

• If we are using a function from libraries,(like printf ,


scanf)
– linker will link our code with that library function code.

BCAC0001 Programming Logic Using C


Atul Kr Uttam
5. Loader
• Loader is the program of the operating system which loads
the executable from the disk into the primary memory(RAM)
for execution.

• It allocates the memory space to the executable module in


main memory and then transfers control to the beginning
instruction of the program

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

/*Below is the Hello-world C program hello.c:*/


#include <stdio.h>
int main()
{
printf("Hello, world!");
return 0;
}

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

$ gcc hello.c
$ ./a.out
Hello, world!

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam
Compile/Link a Simple C Program - hello.c

BCAC0001 Programming Logic Using C


Atul Kr Uttam

You might also like