Compilers

When is the no-optimization setting of a compiler (such as -O0) commonly used?

  1. AWhen building the fastest possible program for release as a product
  2. BWhen hunting bugs by stepping through the program line by line in a debugger
  3. CWhen the program size should be as small as possible
Show answer and explanation

Answer: B. When hunting bugs by stepping through the program line by line in a debugger

Without optimization, each source line maps to machine code in nearly the same order, and variables always remain in memory or registers, making it easy to step line by line in a debugger and inspect variable values. Optimization reorders instructions and removes variables, obscuring the correspondence with the source. Release builds use high optimization levels for speed, and size-oriented settings are used to minimize code size.

  • A. Fast programs use high optimization levels.
  • B. Correct. The clear mapping to source suits debugging.
  • C. Size-oriented settings are used to minimize size.
Practice this topic Back to topic

More Compilers questions

  1. Which describes profile-guided optimization (PGO)?
  2. Which optimization does link-time optimization (LTO) make possible?
  3. In C, signed integer overflow is undefined behavior. Under this rule, which code might an optimizing compiler generate for the function above?
  4. Which program error can be detected at compile time?
  5. What is the main benefit of compile-time type checking in a statically typed language?