NVIDIA Interview Question
Normally the C’s program building process involves four stages and utilizes different ‘tools’ such as a preprocessor, compiler, assembler, and linker.
At the end there should be a single executable file. Below are the stages that happen in order regardless of the operating system/compiler and graphically illustrated in Figure w.1.
Preprocessing is the first pass of any C compilation. It processes include-files, conditional compilation instructions and macros.
Compilation is the second pass. It takes the output of the preprocessor, and the source code, and generates assembler source code.
Assembly is the third stage of compilation. It takes the assembly source code and produces an assembly listing with offsets. The assembler output is stored in an object file.
Linking is the final stage of compilation. It takes one or more object files or libraries as input and combines them to produce a single (usually executable) file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation)
@ joy.vivin
linking:
there are 4 stage when you compile and execute your programme...
1. preprocessing gcc -E your_file_name.c -o final.i
2. Compiling gcc -S final.i -o final.s
3. Assembling gcc -c final.s -o final.o
4. linking gcc -o final.o final
when you write printf function in c programme . at preprossing stage it is replace by actual function calling parameter. it does not know where the defination of printf function is. but at the time of linking it provide information of defination of printf.
if you are using static linking then it will include printf function defination along with executable. if you are using dynamic linking then it will include some information about where to find defination of printf function when you will ececute this programme in anothe machine.
@> let me know if i am wrong.....
Compilation phase : Produces assembly code[Instruction sets defined for the Core].
- Shwetank Gupta October 27, 2009Assembler : Convert assembly instructions into opcode-offset format ..object file[usually a relocatable code].
Linker : Link different object file via resolving references and consolidate them into an executable file.
Let me know if i am wrong or need more explainations :)