Compilers

What is the usual sequence for producing an executable from a C program?

  1. ALink → compile → assemble
  2. BAssemble → link → compile
  3. 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.
Practice this topic Back to topic

More Compilers questions

  1. What is the optimization called that examines short sequences of generated machine code through a small window and replaces wasteful instruction combinations with better ones?
  2. In the code above, which optimization applies after inlining sq, and with what result?
  3. Which describes software pipelining?
  4. Why does a compiler with strict settings not reorder the floating-point sum (a + b) + c into a + (b + c) on its own?
  5. Which kind of instruction does a compiler's automatic vectorization use?