Compilers
When is the no-optimization setting of a compiler (such as -O0) commonly used?
- AWhen building the fastest possible program for release as a product
- BWhen hunting bugs by stepping through the program line by line in a debugger
- 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.