Understand basics of C
Compiling a C program . What are the steps involved?
Compile the file using the command:
gcc –Wall testmacro.c –o testmacro
The following are the steps involved during compilation of a C program. Four differenet tools, preprocessor, compiler, assembler, and linker are used
1. Pre processing
2. Compiling
3 Assembly
4. Liking
1) Pre processing
The preprocessor is a program invoked by the compiler that modifies the source code.
During this phase following things happen
a) Include/Header files are expanded and included in the source code.
b) Comments are removed
c) Macros are replaced
d) conditional compilation instructions
If source code is testmacro.c, the intermediate file, testmacro.i is formed.
2) Compiling
The compiler takes the c soure code and the preprocessor output and generates the assembler source code that has the assembly language instruction.
If the source code is testmacro.c, testmacro.s is the file created
3) Assembly
The assembly language instruction file (test.s) is converted into test.o,object file, that has the machine level instructions. During this phase the function calls (like printf) are not resolved.
4) Linking
In this phase linking of function calls with their definition are done. The linker takes one or more object files or libraries as input and combines them to produce a single (usually executable) file.
The linker, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation).
We get the executable file, testmacro
No comments:
Post a Comment