Compilers
What is the usual sequence for producing an executable from a C program?
- ALink → compile → assemble
- BAssemble → link → compile
- CCompile → assemble → link
Show answer and explanation
Answer: C. Compile → assemble → link
A C source file is first translated by the compiler into assembly language close to machine code (or directly into an object file), then the assembler turns it into a machine-code object file. Finally the linker combines multiple object files and libraries, fixes the addresses of functions and variables and produces the executable. In an object file, addresses of functions in other files are not yet known. In any other order, one stage's output would not be the next stage's input.
- A. Linking is the final stage.
- B. Compilation must precede assembly.
- C. Correct. Compile, assemble, then link.