Computer Science, asked by Abqari63, 9 months ago

When a source code file is compiled and final . exe file is generated it goes through various phases and various components are working in between to generate various kinds of files elaborate each phase and role of each component along with types of files in detail

Answers

Answered by anzarsuleman3
0

Answer:

Below are the steps we use on an Ubuntu machine with gcc compiler.

compilationWe first create a C program using an editor and save the file as filename.c

$ vi filename.c

The diagram on right shows a simple program to add two numbers.

compil31Then compile it using below command.

$ gcc –Wall filename.c –o filename

The option -Wall enables all compiler’s warning messages. This option is recommended to generate better code.

The option -o is used to specify the output file name. If we do not use this option, then an output file with name a.out is generated.

compil21After compilation executable is generated and we run the generated executable using below command.

$ ./filename

What goes inside the compilation process?

Compiler converts a C program into an executable. There are four phases for a C program to become an executable:

Pre-processing

Compilation

Assembly

Linking

By executing below command, We get the all intermediate files in the current directory along with the executable.

$gcc –Wall –save-temps filename.c –o filename

The following screenshot shows all generated intermediate files.

compil4

Let us one by one see what these intermediate files contain.

Pre-processing

This is the first phase through which source code is passed. This phase include:

Removal of Comments

Expansion of Macros

Expansion of the included files.

Conditional compilation

Similar questions